Evaluate the java array to the greatest value.

Source: Internet
Author: User

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 );
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.