Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Q2.

Main class named Q2.java shows the output

Code:-

public class Q2 {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

// TODO code application logic here

matrix m1=new matrix();

m1.show();

}
Class containing the method to be called named matrix.java

Code:-

public class matrix {

void show(){

final int[][] matrix = {

{ 1, 2, 3, 4, 5 },

{ 2, 3, 4, 5, 6 },

{ 3, 4, 5, 6, 7, }

};

for (int[] matrix1 : matrix) {

//this equals to the row in our matrix.

for (int j = 0; j < matrix1.length; j++) {

//this equals to the column in each row.

System.out.print(matrix1[j] + " ");

System.out.println(); //change line on console as row comes to end in the matrix.

You might also like