java - Comparing elements in the same array -
i have array:
int[] times ={ 341, 273, 278, 329, 445, 402, 388, 275, 243, 334, 412, 393, 299, 343, 317, 265, 345, 360, 423 };
i need compare elements , find , output largest number. using java.
any ways helping because purely new programming refer official java tutorials don't expect kind of help every time :)
public class findmax { public static void main(string[] args) { int[] times ={ 341, 273, 278, 329, 445, 402, 388, 275, 243, 334, 412, 393, 299, 343, 317, 265, 345, 360, 423 }; system.out.println("max element: "+ findmax(times)); } //method takes input array of integers , returns max integer public static int findmax(int[] nums){ int max=nums[0]; for(int num :nums){ if(max<num){ max=num; } } homecoming max; } } java
No comments:
Post a Comment