find largest and smallest value in Array
find largest and smallest value in Array:
Code :
public class HelloWorld {
public static void main(String[] args) {
int arr [] = {100,4,3,2,5,687,7,8,5,43,23,65};
int max=0;
int min = 0;
for(int i = 0; i<arr.length;i++){
if(max<arr[i]){
max = arr[i];
}
}
System.out.println("largest Value: "+max);
for(int j = 0; j<arr.length; j++){
if(min > arr[j]){
min = arr[j];
}
}
System.out.print("smallest Value :"+ min);
}
}
Output :
largest Value: 687
smallest Value :0
No comments: