While + Counter Learn programming Java

Lesson:

Flow Control


Exercise:

While + Counter 12


Objetive:

Create a java program to display the numbers 1 to 10 on screen, using "while".


Code:

public class Main
{
	public static void main(String[] args)
	{
		int n = 1;

		while (n <= 10)
		{
			System.out.printf("%1$s ", n);
			n++;
		}
	}
}