Java Program to Print Numbers From 1 to 10 Using For Loop

Java program to read input from user. This is a java program that uses the For Loop to display numbers from 1 to 10.  We use a For Loop to set a variable to 1 and increment it by 1 each time until we reach 10. When variable 11 is reached, the loop ends. 

public class Main
{
public static void main(String[] args)
{
for(int i = 1; i <= 10; i++)
{
System.out.println(i);
}
}
}

 

Output:

1
2
3
4
5
6
7
8
9
10

For Loop in Java Program

The “for” loop in Java is an entry-controlled loop that allows a user to iteratively run a block of statement(s) for a defined number of times. The number of iterations is determined by the test condition specified within the “for” loop. The Java “for” loop is one of the simplest Java loops to grasp. A “For” Loop is used to iterate over a specified block of code a predetermined number of times.