Advertisements
Advertisements
Question
As a homework assignment, your computer teacher has given an incomplete program to accept the integer numbers in a 3x4 double dimensional array. The program has some places left blank marked with ?1?, ?2?, ?3? and ?4? to be filled with appropriate keyword / expression as shown below:
import java.util.*;
class Sum
{
public static void main(String args [])
{
Scanner in=new Scanner(....?1?......);
int 1, j, s = 0;
int m[][] = .........?2?.........;
System.out.println(“Enter the numbers in the matrix”);
for (i = 0; i < 3; i++)
{
for (j = 0; j < 4; j++)
m[i][j] = ........?3?.......;
}
for (i = 0; i < 3; i++)
{
for (j = 0; j < 4; j++)
if (.....?4?.....)
s = s + m[i][j];
}
System.out.println(“Sum of even numbers in the matrix: " + s);
}
}
Based on the above discussion, answer the following questions:
- What keyword / expression will be filled in place of ?1?
- What keyword / expression will be filled in place of ?2?
- What keyword / expression will be filled in place of ?3?
- What keyword / expression will be filled in place of ?4?
Answer in Brief
Solution
- System.in
- new int[3][4]
- in.nextlnt()
- m[i][j] % 2 == 0
shaalaa.com
Is there an error in this question or solution?