Java-Use multiple one-dimensional arrays to achieve storage and output of multiplication.

My own ideas are more ordinary, so I borrow other people's ideas

Own code

public class MultiplicationTable {
    
    
    public static void main(String[] args) {
    
    
        int[] a = new int[9];
        int[] b = new int[9];
        for (int i = 0; i < b.length; i++) {
    
    
            a[i]=i+1;
            b[i]=i+1;
        }
        for (int i = 0; i <a.length ; i++) {
    
    
            for (int j = 0; j <=i ; j++) {
    
    
                System.out.print(a[i]+"*"+b[j]+"="+(a[i]*b[j])+" ");
                if (j == i) {
    
    
                    System.out.println();
                }
            }
        }
    }
}

The code given in the answer

public class Multipation {
    
    
    public static void main(String[] args) {
    
    
    // TODO Auto-generated method stub
    int x[][]=new int[9][9];
    for(int i=0;i<9;i++){
    
    
      for(int j=0;j<9;j++){
    
    
        if(i>=j){
    
    
        int m=i+1;
        int n=j+1;
        x[i][j]=m*n;
        System.out.print(m+"*"+n+"="+x[i][j]);
       }
    }
    System.out.println();
    }
    }
}

Guess you like

Origin blog.csdn.net/qq_41017444/article/details/113791753