I am new to java and I am trying to write the code as followed: user inputs numbers one by one and the code needs to print right away each number and continue to receive the next number on the same row
this is my code so far:
Scanner user = new Scanner(System.in);
String value = user.nextLine();
String matrix = "";
int point = 0;
int pos = 0;
while(pos <= 5)
{
if(isInteger(value))
{
System.out.print(matrix.substring(point) + "\t");
matrix = matrix + value+",";
point+=2;
pos++;
}
else
{
System.out.print("Not a number");
}
value = user.next();
}
but every time I input another number to the scanner when the program is running, it goes down to the next row. so after I type 1 , 2 , 3 , 4 , 5 the output is:
1
2
3
4
5
I want to make it like this:
1 2 3 4 5
is there a way to make the scanner read another number and still remain on the same line?