In this program, we will use the for loop to print tables from 2 to 5.
Program/Source Code:
The source code to implement the nested loop using the for loop is given below. The given program is compiled and executed successfully.
// Java program to implement nested loop
// using the for loop
public class Main {
public static void main(String[] args) {
int cnt1 = 0;
int cnt2 = 0;
for (cnt1 = 2; cnt1 <= 5; cnt1++) {
for (cnt2 = 1; cnt2 <= 10; cnt2++) {
System.out.print((cnt1 * cnt2) + " ");
}
System.out.println();
}
}
}
In this program, we will use the for loop to print tables from 2 to 5.
Program/Source Code:
The source code to implement the nested loop using the for loop is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created a public class Main. It contains a static method main().
The main() method is an entry point for the program. Here, we used a nested for loop to print tables from 2 to 5.
need an explanation for this answer? contact us directly to get an explanation for this answer