Print Numbers 1 to 10
This program prints numbers from 1 to 10 using a for loop.
Problem Statement
Write a Java program that prints numbers from 1 to 10 using a for loop.
Source Code
| 1 | public class PrintNumbers { |
| 2 | public static void main(String[] args) { |
| 3 | for(int i=1; i<=10; i++) { |
| 4 | System.out.println(i + " - Eduinq"); |
| 5 | } |
| 6 | } |
| 7 | } |
Program Output
1 - Eduinq 2 - Eduinq ... 10 - Eduinq
Explanation
The program initializes i=1, checks condition i<=10, and increments i after each iteration. The loop runs 10 times, printing numbers sequentially. This demonstrates the basic structure of a for loop: initialization, condition, and increment. Shows how for loop can print a sequence of numbers.