Java implements a small example of the multiplication table

  • 2020-04-01 02:19:46
  • OfStack

  The code is as follows:


public class NMumDemo {
    public static void main(String args[]){
        int i,j,n=9;
        System.out.print(" * |");
        System.out.print(" 1");
        for(i=2;i<=n;i++)
            System.out.print("  "+i);
        System.out.print("n---|");
        for(i=1;i<=n;i++)
            System.out.print("----");
        System.out.println();
        for(i=1;i<=n;i++){
            System.out.print(" "+i+" |");
            for(j=1;j<=i;j++)
            {
                int test=i*j/10;
                if(test<1) System.out.print(" "+i*j+" ");
                else if(test>=1) System.out.print(" "+i*j);
            }                
            System.out.println();
        }        
    }
}

The effect is as follows:

< img border = 0 SRC = "/ / files.jb51.net/file_images/article/201309/2013930152147974.jpg" >


Related articles: