Sunday, 15 March 2015

java - How do I pass int values from one method to another -



java - How do I pass int values from one method to another -

i'm trying find lowest time in minutes of array int [] times, can't figure out how create sec method work; i'm not getting output.

public static void main(string[] arguments) { string[] names = { "elena", "thomas", "hamilton", "suzie", "phil", "matt", "alex", "emma", "john", "james", "emily", "daniel", "neda", "aaron", "kate" }; int[] times = { 321, 273, 278, 329, 445, 402, 388, 275, 243, 334, 412, 393, 299, 343, 317, 265 }; (int = 0; < names.length; i++) system.out.println(names[i] + ":" + times[i]); }

i don't know it's missing know should lowest time in minutes: 243 (int [] times). "believe" need pass int time values first method sec method...since sense sec method array empty. however, that, don't know how do. help?

public static int getminindex(int[] values) { int minvalue = integer.max_value; int minindex = -1; (int = 0; < values.length; i++) if (values[i] < minvalue) { minvalue = values[i]; minindex = i; } homecoming minindex; //not returning anything. }

the logic of programme is: 1. declaring array of names. 2. declaring array of times. 3. writing names , times through loop console.

you wrote method retrieve minimum value within int array, did not include in program, starts first line of main method.

so first question be, utilize minimum value. , sec question be, minimum value.

suppose want show min value on console, write:

system.out.println(getminvalue(times));

this way method's homecoming value passed static method of system.out argument, suppose want else, pass method accepts int arrays.

java arrays loops return-value min

No comments:

Post a Comment