Advertisements
Advertisements
Question
Fill an array (type int, size 10).
Print its even elements.
Code Writing
Advertisements
Solution
import java.util.*;
class clArrays
{
void main()
{
Scanner sc = new Scanner (System.in);
int R[] = new int [10];
System.out.println("Enter 10 elements for the array : ");
for(int j =0; j <= 9; j++)
{
System.out.print("Fill cell number " + j +“ : ");
R[j] = sc.nextInt();
}
System.out.println("\f The Array elements are : ");
for(int j = 0; j <=9; j++)
{
System.out.print(" " + R[j]);
}
System.out.println("\n\n The Even Array elements are : ");
for(int j = 0; j <= 9; j++)
{
if(R[j]%2=0)
{
System.out.print(" " + R[j]);
}
}
}
}
Output:
The array elements are:
65 62 42 45 84 86 71 73 55 52
The Even Array elements are:
62 42 84 86 52
shaalaa.com
Is there an error in this question or solution?
