具体代码:
public class AdditionTable {
public static void main(String[] args) {
//add();
//add2();
//add3();
add1();
}
public static void add(){
for(int i=2;i<=10;i++){
for(int j=1;j<i;j++){
String format = String.format("%-7s",j+"+"+(i-j)+"="+i);
System.out.print(format);
}
System.out.println(i);
}
}
public static void add1(){
for(int i=10;i>=2;i--){
for(int j=1;j<i;j++){
String format = String.format("%-7s",j+"+"+(i-j)+"="+i);
System.out.print(format);
}
System.out.println(i);
}
}
public static void add2(){
//打印数字
for(int i=2;i<=10;i++){
System.out.print(i +" ");
}
System.out.println();
//打印分解符
for (int i= 2;i<=10;i++){
System.out.print("/\\ ");
}
System.out.println();
for(int n = 1;n <= 9;n++) {
//循环打印空格
for(int j=0;j<n-1;j++){
System.out.print(" ");
}
//打印相应的数字
for (int i = 1; i <= 10-n; i++) {
System.out.print( n+" " +i+" ");
}
System.out.println();
}
}
public static void add3(){
//打印数字
for(int i=10;i>=2;i--){
System.out.print(i +" ");
}
System.out.println();
//打印分解符
for (int i=10;i>=2;i--){
System.out.print("/\\ ");
}
System.out.println();
for(int n = 1;n <= 9;n++) {
//打印相应的数字
for (int i = 10-n; i >= 1; i--) {
System.out.print( n+" " +i+" ");
}
System.out.println();
}
}
}