Write a program to create an array to store 10 integers and print the largest and smallest integer in that array
Answers
Answer:
This program Finds the Largest Number and the Smallest Number present in the Array Variable.
It uses for loop to iterate the array upto the end of its index value and if conditions evaluates the biggest and smallest numbers and
that store in the specified variable.
"
public class FindBiggestSmallestNumber {
public static void main(String[] args) {
int numbers[] = new int[]{33,53,73,94,22,45,23,87,13,63};
int smallest = numbers[0];
int biggest = numbers[0];
for(int i=1; i< numbers.length; i++)
{
if(numbers[i] > biggest)
biggest = numbers[i];
else if (numbers[i] < smallest)
smallest = numbers[i];
}
System.out.println("Largest Number is : " + biggest);
System.out.println("Smallest Number is : " + smallest);