• Post Reply Bookmark Topic Watch Topic
  • New Topic

I'm stuck on this array assignment  RSS feed

 
Artmir Galica
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The assignment is as follows:

The Java-program Matrix below first asks the user for the number of rows and columns in a matrix. After this the program asks for the values of the elements. Finally, program prints the elements of the matrix and their sum on screen. Your task is to create the missing methods. Check the example print to see how to modify the print. When printing the matrix, values on the same row are separated using tabulator.

import java.util.Scanner;

public class Matrix {

public static void main(String[] args) {

int rows, columns;

Scanner reader = new Scanner(System.in);

System.out.print("Type in the number of rows: ");
rows = reader.nextInt();

System.out.print("Type in the number of columns: ");
columns = reader.nextInt();

int matrix [][];

matrix = askInfo(rows, columns);
printMatrix(matrix);
countSum(matrix);
}

// Write the missing methods here

}
Example output looks like this:

Type in the number of rows: 3
Type in the number of columns: 4
Type in the element 1 of the row 1: 1
Type in the element 2 of the row 1: 2
Type in the element 3 of the row 1: 3
Type in the element 4 of the row 1: 4
Type in the element 1 of the row 2: 5
Type in the element 2 of the row 2: 6
Type in the element 3 of the row 2: 7
Type in the element 4 of the row 2: 8
Type in the element 1 of the row 3: 9
Type in the element 2 of the row 3: 10
Type in the element 3 of the row 3: 11
Type in the element 4 of the row 3: 12

Matrix:
1 2 3 4
5 6 7 8
9 10 11 12

Sum of the elements of the matrix: 78
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> The assignment is as follows:

And your question is?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!