Home » Java solved programs » Core java programs

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






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.