Good job! The program works!
Some things can be done now.
- reformat the code to give clarity
- give meaningful names to variables
- put comments to explain what are you doing
- expressing the solution in a more straightforward and simple way
- etc
This kind of things are very important. I'm gonna do the first three. This is your program with very little modifications:
public class FirstProgramme {
public static void main(String[] args) {
// get max number to print
System.out.print("Please enter a number: ");
Scanner in = new Scanner(System.in);
int maxNumber = in.nextInt();
// --------------------------------------------------
// print numbers from 1 to maxNumber
// --------------------------------------------------
int number = 1;
// while I have numbers to print
while ( number<maxNumber ) {
int count = 0; // count for numbers printed in the line
// print next 5 numbers in the line
while( count <= 4 ) {
System.out.print(number + " " );
number++; // next number to print
count++; // now we have another number printed in the line
// if we have printed all the numbers, exit
if (number == maxNumber) {
break;
// otherwise, jump to the next line every 5 numbers
} else if (count == 5) {
System.out.println();
}
}
}
// --------------------------------------------------
}
}