+ 1
Why this code is not producing the output in matrix form(rectangle form )?????
class Demo { public static void main(String arg[]) { int a[][]=new int[3][3]; System.out.println("Enter the elements of array : "); for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { a[i][j]=s.nextInt(); } } for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { System.out.println(a[i][j]+" "); } System .out.println(); } } }
1 Answer
+ 2
My guess is, you are using println inside a loop(inner loop). Which actually print the argument with end of line at the end. So output should be like this,
1
2
3
instead you can use print method.
Hope this will help you