无法搭建表格的第一行和第一列,第一行和第一列都是0 1 2 3 4 5 6 7 8 9 10 11 12
public class A2 {
public static void main(String[] args) {
for(int i=0; i<=12; i++){
for(int j=0; j<=12;j++){
System.out.print(j*i+"\t");
}
System.out.println();
}
}
}
尝试再嵌套一层代码将第一行与第一列剥离出来,但是失败;
尝试使用两个并列循坏,还是不行
零界点 判断处理一下就可以了,参考一下 有用的话 采纳
public static void main(String[] args) {
for(int i=0; i<=12; i++){
for(int j=0; j<=12;j++){
if (j == 0){
System.out.print(i+"\t");
continue;
}
if (i == 0){
System.out.print(j+"\t");
continue;
}
System.out.print(j*i+"\t");
}
System.out.println();
}
}
}
public class Test{
public static void main(String[] args) {
for (int i = 0; i <=12; i++) {
for (int j=0; j <=12; j++) {
//如果不是第一行和第一列,就打乘积
if(i!=0&&j!=0) {
System.out.print(i*j+"\t");
}else {
//如果是第一行或第一列,就打i,j的和,因为若是第一行或第一列,则i,j必有一个为0,另一个会继续加加,只需二者加起来即可
System.out.print(j+i+"\t");
}
}
System.out.println();
}
}
}
实现的方法有好多种,我就用你的代码这种来改一下