So i want my output to be something like this:
N = 3
userinput1 | userinput2 | userinput3
userinput4 | userinput5 | userinput6
userinput7 | userinput8 | userinput9
but the problem is after i insert my userinput1 and press enter it goes one space below and become like this
1
| 2
| 3
|
4
| 5
| 6
|
7
| 8
| 9
|
i tried to change sc.nextInt(); to sc.nextLine(); but it doesnt work even after i used parseInt ..
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);int[][] noOfArrays;
int noOfRows;
int noOfColumns;
System.out.println("Output : ");
System.out.print("Input N = ");
noOfRows = sc.nextInt();
noOfColumns = noOfRows;
noOfArrays = new int[noOfRows][noOfColumns];
///////////////////////////////
for(int i = 0; i{
for(int j=0; j{
noOfArrays[i][j] = sc.nextInt();
System.out.print(" | ");
}
System.out.println("");
}
}
No comments:
Post a Comment