×

Java Programs

Java Practice

Java program to print numbers from 1 to 10 using while loop

This is an Example of java while loop - In this java program, we are going to print numbers from 1 to 10 using while loop.
Submitted by Chandra Shekhar, on March 09, 2018

To print numbers from 1 to 10, we need to run a loop (we are using while loop here), logic to print numbers:

  • In this program, we included a package named ‘IncludeHelp’ which is on my system, you can either remove it or include your package name, in which program’s source code is saved.
  • Initializing a loop counter (i) with 1 and while condition to check loop counter whether it is less than or equal to 10, if condition is true, numbers will be printed using System.out.println() that will print numbers in new line.

Example:

    Numbers from 1 to 10
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

Program to print the number from 1 to 10 using while loop in java

package IncludeHelp;

public class Print_1_To_10_UsingWhile 
{
	public static void main(String args[])
	{
		//loop counter initialisation
		int i=1;

		//print statement
		System.out.println("Output is : ");

		//loop to print 1 to 10.
		while(i<=10)	
		{
			System.out.println(i);
			i++;
		}
	}
}

Output

Output is : 
1
2
3
4
5
6
7
8
9
10

Core Java Example Programs »



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.