Sololearn: Learn to Code
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 3
it's a bit unclear. Do you mean something like this? public class Main { public static void main(String[] args) { int[][] a = { {1, 2, 3}, {4, 5, 6} }; for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) { System.out.printf("%d ", a[i][j]); } System.out.println(); } } } out: 1 2 3 4 5 6
12th Dec 2020, 12:06 PM
Flash
+ 3
I think this lesson is what u r asking for : https://www.sololearn.com/learn/Java/2149/?ref=app
12th Dec 2020, 12:38 PM
Alphin K Sajan
Alphin K Sajan - avatar
+ 3
in Java11+ you can try this as well import java.util.Arrays; public class Main { public static void main(String[] args) { int[][] matrix = { {8, 1, 6}, {3, 5, 7}, {4, 9, 0}, }; for (var i : matrix) { System.out.println(Arrays.toString(i)); } } } out; [8, 1, 6] [3, 5, 7] [4, 9, 0]
12th Dec 2020, 12:47 PM
Flash
+ 3
Most Welcome 🙂, Ok No Problem.
12th Dec 2020, 2:04 PM
Mohammed Qadir khan
Mohammed Qadir khan - avatar
+ 2
If you use System.out.println() it'll print a newline characters at end of string. If you have already tried to solve this please share your code here so others can see what's wrong in it. If you don't know how to share code read this: https://www.sololearn.com/post/75089/?ref=app
12th Dec 2020, 11:42 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 2
Flash, Starting from Java 10, actually. https://developer.oracle.com/java/jdk-10-local-variable-type-inference.html For lower versions of Java that var can be replaced by int[] for(int[] a: matrix) {}
12th Dec 2020, 12:53 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
12th Dec 2020, 12:59 PM
Flash
0
Aysha Simra where did get 2? what kind of order is that?
12th Dec 2020, 12:56 PM
Flash