请给出一个输出9*9乘法表的算法

来源:百度知道 编辑:UC知道 时间:2024/05/10 23:24:19

2*1=2
3*1=3 3*2=6
4*1=4 4*2=8 4*3=12
5*1=5 5*2=10 5*3=15 5*4=20
6*1=6 6*2=12 6*3=18 6*4=24 6*5=30
7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42
8*1=8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56
9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72
Press any key to continue

那我写个C++

#include<iostream>
using namespace std;

main()
{
for (int i = 1; i < 10; i++)
{
for (int j = 1; j < i; j++)
cout<<i<<'*'<<j<<'='<<(i*j)<<' ';
cout<<endl;
}
}

//JAVA代码
public class Test{
public static void main(String[] args)
{
Label: for(int a=1;a<=9;a++){
for(int b=1;b<=9;b++){
if(b>a){
System.out.println();
continue Label;
}
System.out.print(b+"×"+a+"="+a