格式1:
package chengfa; public class Chengfabiao { public static void main(String[] args) { // TODO Auto-generated method stub for(int i=1;i<=9;i++){ for(int j=1;j<=i;j++){ //System.out.printf("%d%c%d%c%2d\t",i,'*',j,'=',i*j); System.out.print(i+"*"+j+"="+i*j+(j==i? "":"\t"));//*和=必须用双引号 }System.out.println(); } } }
格式2:
package chengfa; public class Chengfabiao { public static void main(String[] args) { // TODO Auto-generated method stub for(int i=1;i<=9;i++){ for(int j=1;j<10;j++){ //System.out.printf("%d%c%d%c%2d\t",i,'*',j,'=',i*j); System.out.print(i+"*"+j+"="+i*j+(j==i? "\t":"\t"));//*和=必须用双引号 }System.out.println(); } } }
格式3:
package chengfa; public class Chengfabiao { public static void main(String[] args) { // TODO Auto-generated method stub for(int i=9;i>=1;i--){ for(int j=1;j<=i;j++){ //System.out.printf("%d%c%d%c%2d\t",i,'*',j,'=',i*j); System.out.print(i+"*"+j+"="+i*j+(j==i? "\t":"\t"));//*和=必须用双引号 }System.out.println(); } } }
格式4:
package chengfa;
public class Chengfabiao {
public static void main(String[] args) {
// TODO Auto-generated method stub
for(int i=1;i<10;i++){
for(int k=0;k<=(9-i)*7;k++){
System.out.print(" ");
}
for(int j=1;j<=i;j++){
System.out.printf("%d*%d=%2d ",i,j,j*i);
// System.out.print(i+"*"+j+"="+i*j+"\t");//*和=必须用双引号
}System.out.println();
}
}
}
格式5:
package chengfa; public class Chengfabiao { public static void main(String[] args) { // TODO Auto-generated method stub for(int i=9;i>0;i--){ for(int k=0;k<=(9-i)*7;k++){ System.out.print(" "); } for(int j=1;j<=i;j++){ System.out.printf("%d*%d=%2d ",i,j,j*i); //System.out.print(i+"*"+j+"="+i*j+"\t");//*和=必须用双引号 }System.out.println(); } } }