java求解九九乘法表,我的错误在哪啊,请各位高手帮帮忙啊!

来源:百度知道 编辑:UC知道 时间:2024/06/26 05:10:02
这是我编的
public class m4 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int mult[][]=new int[10][];
mult[0]=new int[1];
mult[1]=new int[2];
mult[2]=new int[3];
mult[3]=new int[4];
mult[4]=new int[5];
mult[5]=new int[6];
mult[6]=new int[7];
mult[7]=new int[8];
mult[8]=new int[9];
mult[9]=new int[10];

int a,b;
for(a=0;a<10;a++)
for(b=0;b<a+1;b++){
mult[a][b]=a*b;
if(mult[a][b]==0)
continue;

}
for(a=0;a<10;a++){
for(b=0;b<a+1;b++)
System.out.print(mult[a][b]+" ");
System.out.println();
}

运行之后答案是:
0
0 1
0 2 4
0 3 6 9
0 4 8 12 16
0 5 10 15 20 25
0 6 12 18 24 30 36
0 7 14 21 28 35 42 49
0 8 16 24 32 40 48 56 64
0 9 18 27 3

只要结果的话两个循环直接就行,不必再运行过程中保存结果
public class chengFaBiao {
public static void main(String[] args) {
int a=0,b=0;
for(a=1;a<10;a++) {
for(b=1;b<a+1;b++)
System.out.print(a*b + " ");
System.out.println("");
}
}
}

netBeans下运行结果:
init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\GSY\JavaApplication1\build\classes
compile-single:
run-single:
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
6 12 18 24 30 36
7 14 21 28 35 42 49
8 16 24 32 40 48 56 64
9 18 27 36 45 54 63 72 81
BUILD SUCCESSFUL (total time: 0 seconds)

你做得没错,能输出0说明你充分考虑了边界值问题,只要在输出时跳过0就行,或者在计算a*b时直接从1开始,毕竟乘法表里没有与0有关系的

class NumTable {
public static void main(String args[]){
System.out.println("乘法口诀表");
for(int i=1;