-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiagonally.java
More file actions
60 lines (46 loc) · 1.74 KB
/
Copy pathDiagonally.java
File metadata and controls
60 lines (46 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// library for the scannner
import java.util.Scanner;
import java.util.Arrays;
public class Diagonally {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println(" " );
System.out.println("Enter the number of row of the first matrix : " );
int numberOfRowMatrix1 = scan.nextInt();
System.out.println(" " );
System.out.println("Enter the number of column of the first matrix : " );
int numberOfCulumnMatrix1 = scan.nextInt();
int callFM1[][]= fillMatrix1(numberOfRowMatrix1,numberOfCulumnMatrix1);
System.out.println("The first matrix is : ");
printer(callFM1);
}
public static int[][] fillMatrix1 (int r1,int c1) {
int[][] matrix1 = new int[r1][c1];
Scanner scan = new Scanner(System.in);
for(int i=0; i<r1; i++ ) {
for(int j=0; j<c1; j++) {
System.out.println("Enter element "+ i + " ," + j);
matrix1[i][j] = scan.nextInt();
}
}
return matrix1;
}
public static void printer(int mat[][]) {
for(int i =0; i<mat.length; i++)
System.out.println(Arrays.toString( mat[i]));
System.out.println();
}
public static void diagonalPrint (int[][] M) {
int widch= M.length ;
int height = M[0].length ;
String[][] array = new String[height][];
for( int i = 0 ; i < height ; i++ ) {
for( int j = 0 ; j < widch ; j++ ) {
System.out.print( array[i][j] + " " );
}
System.out.println();
}
System.out.println( "============================" );
return ;
}
}