public class Print_Min_Max_Value {
public static void main(String[] args)
{
int i; //loop counter
int[] arr=new int[]{10,20,90,50}; //arrays
int min=arr[0]; //set values for comparison from start to end of the array
int max=arr[0]; //set values for comparison from start to end of the array
for (i=0;i<arr.length;i++)
{
if(arr[i]>max)
{
max=arr[i];
}
else if(arr[i]<min)
{
min=arr[i];
}
}
System.out.println(max);
System.out.println(min);
}
}
output:
90
10
No comments:
Post a Comment