0
I want to print the elements of a matrix but I don't know what's the problem
import java.util.Scanner; public class method3 { public static void main(String[]args) { Scanner scanner= new Scanner(System.in); int m=scanner.nextInt(); int n=scanner.nextInt(); int [][] matrix =new int [m][n]; for(int i=0;i<m;i++) { for ( int j=0;j<n;j++) { matrix [i][j]=scanner.nextInt(); } } scanner.close(); for(int i=0;i<m;i++) { for ( int j=0;j<n;j++) { System.out.print(matrix[i][j]); } } } }
4 Answers
+ 2
Thanks a lot for your help.
How can I insert a link in SL playground?
+ 1
There is no problem with your code, it works fine.
If I give the input: 2 2 3 4 5 6
It prints: 3456
Next time please insert a link to your code in SL playground, so that it is easier to test and debug.
+ 1
Thanks a lot