In this example we will show how to use while loop in Java.
Source Code
package com.beginner.examples;
public class WhileLoop {
public static void main(String[] args) {
int a = 1;
while (a < 3) { // use while loop
System.out.println(a);
a++;
}
}
}
Output:
1
2