Evaluate the java array to the greatest value.
In java, the array is the best value, which is rarely used in actual development, but will be occasionally asked during the interview. This is your basic thinking ability. Now let's talk about the basic idea of this question.
Ideas:
1: Define a variable first. Generally, the first value of the array is used.
2: in the loop, determine whether (from the second badge to the value corresponding to the length-1 badge of the array) is greater than the previously defined value, if the value is greater than that, assign this value to max until the maximum value is obtained.
The Code is as follows:
public static void main(String[] args) {int[] arr = {1,3,5,6,9,7};int max = arr[0];for(int i=1;i<arr.length;i++){if(arr[i]>max){max = arr[i];}}}
JAVA programming array maximum and minimum values
Be careful later, you are at the end
System. out. print ("max =" + max );
System. out. print ("min =" + max );
Same, so the input is the same. In the future, note that JAVA is more important to java ee programming. In fact, these algorithms do not need to be too concerned and hope to be useful to you!
Public class {
Public static void main (String args []) {
Int a [] = };
Int n;
Int min = a [0];
Int I;
Int max = a [0];
For (n = 0; n <= 9; n ++ ){
If (max <a [n])
Max = a [n];
}
For (I = 0; I <= 9; I ++ ){
If (min> a [I])
Min = a [I];
}
System. out. print ("max =" + max );
System. out. print ("min =" + min );
}
}
Java array maximum value
Import java. util. collections;
Public class max {
Public static void main (String args []) {
Repeated scan = new partition (System. in );
Double [] g = new double [10];
Double tem = 0.0;
For (int k = 0; k <= 9; k ++ ){
G [k] = scan. nextDouble ();
}
Int I, j = 0;
For (I = 0; I <9; I ++ ){
If (g [j] <g [I + 1]) {
Tem = g [I + 1];
J = I + 1;
}
}
System. out. println ("max =" + tem );
}
}