Computer Science, asked by anaborah77, 7 hours ago

write a program to input 10 numbers in a sda and find the largest even number​

Answers

Answered by BrainlyProgrammer
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

a[] =  \boxed{  \:  | \:  | \:  | \:  | \:  |  \: | \: | \:  | \:  | \: }

  • Let us take an array of 10 numbers as input, it will store the 10 numbers as follows:

a[] =  \boxed{12 | 36|8 |1 |3| 79|94 | 5| 2 |12}

  • 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