While + Counter Learn programming Java

Lesson:

Flow Control


Exercise:

While + Counter


Objetive:

Create a java program to display the numbers 1 to 10 on the 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++;
		}
	}
}

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.