[Solved] How to print 10 numbers per line in java


while loops? Why not use for loops? They are much better in this kind of situation i.e. when you want to repeat something a known number of times.

You can use a nested for loop to make this happen:

int counter = 0;
for (int i = 0 ; i < 10 ; i++) {
    for (int j = 0; j < 10 ; j++) {
        System.out.print (counter);
        System.out.print (" "); // I think it is best to have spaces between the numbers
        counter++;
    }
    //after printing 10 numbers, go to a new line
    System.out.println ();
}

4

solved How to print 10 numbers per line in java