Assignment: Module 03- Part 02
Write a class LoopExample1 to display the output as below using control structures.
Enter the no of terms 3
Output:
i=1
i=2
i=3
import java.util.Scanner;
public class LoopExample1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the no of terms: ");
int n = sc.nextInt();
for (int i = 1; i <= n; i++) {
System.out.println("i=" + i);
}
}
}
Example output:
Enter the no of terms: 3
i=1
i=2
i=3