write a program to input 10 numbers in a sda and find the largest even number
Answers
Answered by
2
Answer:
import java.util.*;
class number{
public static void main (String ar []){
Scanner sc=new Scanner (System.in);
int a[]=new int[10];
System.out.println("Enter 10 numbers");
for(int I=0;I<10;I++)
a[I]=sc.nextInt();
int max=0;
for(int I=0;I<10;I++)
max=((a[I]>max)&&(a[I]%2==0))?a[I]:max;
System.out.println("Largest even number:"+max);
}
}
What is happening above?
- When the program runs, it will first allocate space for an array as follows
- Let us take an array of 10 numbers as input, it will store the 10 numbers as follows:
- then the loop runs from 0 to 10 checking the largest even number
- when the loop ends, we get 94 as the largest even number which is printed as last.
Attachments:
Similar questions