Tables in java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Tables in java

I'm trying to program a Table for a game in java, but thats the result of my code and I can't solve how to print it in matrix form instead of that column. Any idea what's happenning? Thx. https://code.sololearn.com/c5xLL1wm147B

10th Feb 2018, 10:57 AM
Pau Bartolí
Pau Bartolí - avatar
3 Answers
+ 19
import java.util.*; /** * * @author Bartokid */ public class soloLearn { /** * write 1 number then press enter an write the next number :) */ public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.println("Escriba el numero de filas:"); int columns=s.nextInt(); System.out.println("Escriba el numero de columnas:"); int lines=s.nextInt(); System.out.println("Numero de Filas: "+ lines); System.out.println("Numero de columnas: "+ columns); for(int i=0;i<columns;i++){ for(int j=0;j<lines;j++){ System.out.print("| |\t"); } System.out.println("\n"); } } }
10th Feb 2018, 12:29 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 7
//i made this hope it helps int arr [][] = {{1,2,3,4},{3,2,1,0},{9,8,7,6}}; for(int i = 0; i<arr.length;++i){ for(int j = 0; j<arr[i].length;++j){ System.out.print(arr[i][j]+" "); } System.out.println(); }
10th Feb 2018, 12:08 PM
D_Stark
D_Stark - avatar
+ 3
thanks you all, code edited :) https://code.sololearn.com/c5xLL1wm147B
10th Feb 2018, 12:45 PM
Pau Bartolí
Pau Bartolí - avatar