Group Discussion- Nested Loop Scope Chain.docx - Part 1 What this one says package lectures.chapter05 public class MultiplicationTable Main method

# Group Discussion- Nested Loop Scope Chain.docx - Part 1...

• 5

This preview shows page 1 - 4 out of 5 pages.

Part 1:What this one says:package lectures.chapter05;public class MultiplicationTable {/** Main method */ public static void main(String[] args) { // Display the table heading System.out.println(" Multiplication Table");// Display the number title System.out.print(" "); for (int j = 1; j <= 9; j++) System.out.print(" " + j);System.out.println("\n-----------------------------------------");// Print table body
// int j=1, j=1; // if you declare i and j outside the for loop; you need to make sure j is properly initialized // for every new outer loop// for loop with i is the outer loop for (int i = 1; i <= 9; i++) {System.out.print(i + " | "); // for loop with j is the inner loopfor (int j = 1; j <= 9; j++) { // Display the product and align properly System.out.printf("%4d", i * j);} System.out.println(); } }}Part 2:
What this one says:package lectures.chapter05;public class MultiplicationTable {/** Main method */ public static void main(String[] args) { // Display the table heading System.out.println(" Multiplication Table");// Display the number title System.out.print(" "); for (j = 1; j <= 9; j++) System.out.print(" " + j);System.out.println("\n-----------------------------------------");// Print table body // int j=1, j=1;