package com.tutorial4u;
public class LargestAndSmallestArray {
public static void main(String[] args) {
int arraylist[] = {12,34,21,24,54,32,76};
int smallestArray = arraylist[0];
int largestArray = arraylist[0];
for(int i =1 ;i< arraylist.length;i++){
if(arraylist[i] > largestArray){
largestArray = arraylist[i];
}else if(arraylist[i] < smallestArray){
smallestArray = arraylist[i];
}
}
System.out.println("Smallest Number in Array is : "+smallestArray);
System.out.println("Largest Numbe rin Array is : "+largestArray);
}
}
Smallest
Number in Array is : 12
Largest
Numbe rin Array is : 76
No comments:
Post a Comment