用Java写出下图的九九乘法表

img


已写了大概的代码,但不知道如何得出如图所示的结果
public static void main(String[] args) {

    for(int i=1;i<=9;i++){
           for(int j=1;j<=i;j++){
               System.out.print(j+" "+i+"  "+(i*j)+"\t");
           }
           System.out.println(" ");
       }
}

}

package com;

public class Main {

    public static void main(String[] args) {
        
        System.out.println("             99乘法表                ");
        System.out.println("   1  2  3  4  5  6  7  8  9");
        System.out.println("____________________________________");
        System.out.println();
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= i; j++) {
                if (j == 1) {
                    System.out.print(i + "| " + i * j + " ");
                } else {
                    System.out.print(i * j + " ");
                }
            }
            System.out.println(" ");
        }
    }

}

img

双层for循环遍历输出即可
代码及运行结果如下:

img


public class Test {
    public static void main(String[] args){
        
        //输出上面的行
        System.out.print("|   ");
        for(int i=1;i<=9;i++){
            if(i<=8)
                System.out.print(i+"  ");
            else
                System.out.println(i);
        }
        System.out.println("--------------------------------");
        System.out.println("|");
        for(int i=1;i<=9;i++){
            System.out.print("|"+i+"| ");
            for(int j=1;j<=i;j++){
                System.out.printf("%-3d",i*j);
            }
            System.out.println();
        }
        
    }

}

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: Negen
 * @Date: 2022/04/07/16:26
 * @Description:
 */
public class Demo {
    public static void main(String[] args) {
        for(int i=1;i<=9;i++){
            for(int j=1;j<=i;j++){

                System.out.print(j+"*"+i+"="+j*i+"\t");
            }
            System.out.println();
        }
    }
}

img

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632