write a program to input any 10 numbers in single dimensional array and print only those numbers which are even. (Using Scanner Class)
Answers
public class FindLargestSmallestNumber
{
public static void main(String[] args)
{
Scanner input = new Scanner(system.in);
//array of 10 numbers
int numbers[10] ;
System.out.println("Enter 10 number in an Array");
for (i=0;i<10;1++)
{
numbers[i]=input.nextInt();
}
//assign first element of an array to largest and smallest
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);
}
}