for loop java code code example
Example 1: for loop java
for(int i = 0; i < 5; i++) {
System.out.println(i + 1);
}
for(int i = 1; i <= 5; i++) {
System.out.println(i);
}
Example 2: java for loop
import java.util.Scanner;
public class grepperjava {
public static void main(String[] ARGS)
{
System.out.println("\nPlease enter a number, and the loop will iterate input times.");
int input;
Scanner var = new Scanner(System.in);
input = var.nextInt();
var.close();
for(int i = 0; i < input; i++)
{
System.out.println("This will print " + input + " times");
}
}
}