package practice;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
public class Practice {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
StringBuilder output = new StringBuilder();
System.out.println("Enter the number of rows & columns: ");
System.out.print("Enter the number of rows: ");
int row = input.nextInt();
System.out.print("Enter the number of columns: ");
int columns = input.nextInt();
int [][]nums = new int[row][columns];
for (int i = 0; i < row; i++)
{
for (int j = 0; j < columns; j++)
{
System.out.print("Number " + (j + 1) + ": ");
nums[i][j] = input.nextInt();
output.append("\n").append(nums[i][j]);
}
System.out.println( " " );
}
System.out.println(output);
}
}
I have a problem with the code shown above, I'm practicing multi-dimensional array. What I want is to make a list of numbers in which they are separated by rows and columns, Example: if I entered 3 in the rows and 4 in the column the output numbers should be arranged like this.
10 20 30 40
50 60 70 80
90 100 101 102
But that problem is the output showing is a long line of continuous numbers. can anyone help me to solve this issue,
Thank you,
\nafter every forth entry.