Computer Applications
If arrays M and M + N are as shown below, write a program in Java to find the array N.
M = {{-1, 0, 2}, M + N = {{-6, 9, 4},
{-3, -1, 6}, {4, 5, 0},
{4, 3, -1}} {1, -2, -3}}
Java
Java Arrays
35 Likes
Answer
public class KboatSubtractDDA
{
public static void main(String args[]) {
int arrM[][] = {
{-1, 0, 2},
{-3, -1, 6},
{4, 3, -1}
};
int arrSum[][] = {
{-6, 9, 4},
{4, 5, 0},
{1, -2, -3}
};
int arrN[][] = new int[3][3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
arrN[i][j] = arrSum[i][j] - arrM[i][j];
}
}
System.out.println("Array N:");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
System.out.print(arrN[i][j]);
System.out.print(' ');
}
System.out.println();
}
}
}
Variable Description Table
Program Explanation
Output
Answered By
14 Likes
Related Questions
A Metropolitan Hotel has 5 floors and 10 rooms in each floor. The names of the visitors are entered in a Double Dimensional Array (DDA) as M[5][10].The Hotel Manager wants to know from the "Enquiry" about the position of a visitor (i.e. floor number and room number) as soon as he enters the name of the visitor. Write a program in Java to perform the above task.
A Class Teacher wants to keep the records of 40 students of her class along with their names and marks obtained in English, Hindi, Maths, Science and Computer Science in a Double Dimensional Array (DDA) as M[40][5]. When the teacher enters the name of a student as an input, the program must display the name, marks obtained in the 5 subjects and the total. Write a program in Java to perform the task.
A double dimensional array is defined as N[4][4] to store numbers. Write a program to find the sum of all even numbers and product of all odd numbers of the elements stored in Double Dimensional Array (DDA).
Sample Input:12 10 15 17 30 11 32 71 17 14 29 31 41 33 40 51
Sample Output:
Sum of all even numbers: ……….
Product of all odd numbers: ……….A Departmental Shop has 5 stores and 6 departments. The monthly sale of the department is kept in the Double Dimensional Array (DDA) as m[5][6]. The Manager of the shop wants to know the total monthly sale of each store and each department at any time. Write a program to perform the given task.
(Hint: Number of stores as rows and Number of departments as columns.)