package
javaprgms;
public class Array
{
public static void main(String[] args) {
int arr[]={1,120,56,78,87};
int largest=arr[0];
int smallest=arr[0];
int small=0;
int index=0;
for(int i=1;i<arr.length;i++){
if(arr[i]>largest){
largest=arr[i];
index=i;
}
else if(smallest>arr[i]){
smallest=arr[i];
small=i;
}
}
System.out.println("Largest
number : "+largest);
System.out.println("Largest
number index : "+index);
System.out.println("smallest
number : "+smallest);
System.out.println("smallest
number index : "+small);
}
}
Output:
Largest number : 120
Largest number index :
1
smallest number : 1
smallest number index : 0
No comments:
Post a Comment