目 录CONTENT

文章目录

Java Implementation of 99 Multiplication Table — Using For Loop and Recursion

zeruns
2024-12-28 / 0 Comment / 1 Like / 4 Views / 0 words / It is currently checking whether it has been included...

Java Implementation of 99 Multiplication Table

For Loop


public class ninenine {
    public static void main(String[] args){
        for (int i=1;i<10;i++) {
            for(int j=1;j<=i;j++) {
                System.out.printf("%d*%d=%d\t",j,i,j*i);
            }
            System.out.println("");
        }
    }
}

Recursion


public class MultiTable {
 public static void main(String args[]) { 
    m(9); 
  } 
  
  /** 
   * Prints the 99 Multiplication Table 
   * https://blog.zeruns.com
   */
  public static void m(int i) { 
    if (i == 1) { 
      System.out.println("1*1=1 "); 
    } else { 
      m(i - 1); 
      for (int j = 1; j <= i; j++) { 
        System.out.print(j + "*" + i + "=" + j * i + " "); 
      } 
      System.out.println(); 
    } 
  }  
}

1

Comment Section