Java program to find the min and max number from a given array
KW.java
classKW{publicstaticvoidmain(Stringargs[]){System.out.println("———————————————————————————————————————————");System.out.println("Implementation of Java arrays ");System.out.println("———————————————————————————————————————————");double[]a={100,15,15.15,400,45.99};System.out.println("Array contains the following numbers"+"\n{");for(doublearr:a)System.out.println(" "+arr);doublesum=0;for(inti=0;i<a.length;i++){sum=sum+a[i];}System.out.println("}\nThe addition of array is = "+sum);doublemax=a[0];doublemin=max;for(inti=0;i<a.length;i++){if(a[i]>max)max=a[i];if(a[i]<min)min=a[i];}System.out.println("\nThe max number from a given array is "+max);System.out.println("\nthe min number from a given array is "+min);System.out.println("———————————————————————————————————————————");}}
Output
kodingwindow@kw:~$ javac KW.java kodingwindow@kw:~$ java KW
———————————————————————————————————————————
Implementation of Java arrays
———————————————————————————————————————————
Array contains the following numbers
{
100.0
15.0
15.15
400.0
45.99
}
The addition of array is = 576.14
The max number from a given array is 400.0
The min number from a given array is 15.0
———————————————————————————————————————————
kodingwindow@kw:~$
Dear User, Thank you for visitng KodingWindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.