public class FindLargestSmallestNumber {
public static void main(String[] args) {
int numbers[] = new int[]{45,44,35,50,17,58,78,99,40,13};
int smallest = numbers[0];
int largetst = numbers[0];
for(int i=1; i< numbers.length; i++)
{
if(numbers[i] > largetst)
largetst = numbers[i];
else if (numbers[i] < smallest)
smallest = numbers[i];
}
System.out.println("Largest Number is : " + largetst);
System.out.println("Smallest Number is : " + smallest);
}
}
/*
Output of this program would be
Largest Number is : 99
Smallest Number is : 13
*/
public static void main(String[] args) {
int numbers[] = new int[]{45,44,35,50,17,58,78,99,40,13};
int smallest = numbers[0];
int largetst = numbers[0];
for(int i=1; i< numbers.length; i++)
{
if(numbers[i] > largetst)
largetst = numbers[i];
else if (numbers[i] < smallest)
smallest = numbers[i];
}
System.out.println("Largest Number is : " + largetst);
System.out.println("Smallest Number is : " + smallest);
}
}
/*
Output of this program would be
Largest Number is : 99
Smallest Number is : 13
*/
No comments:
Post a Comment