标签:long double 名称 main out system 嵌套 return sum
1.while循环九九乘法表:
class TriangleDemo{ public static void ninexjiu(){ int line=9; int row=1; while(row<=9){ int col=9; while(col >=row){ System.out.print(col+"*" +row+"="+ (col *row)+"\t"); col--; } row++; System.out.println(); } } public static void main(String[] args){ //TriangleDemo t=new TriangleDemo(); // t.ninexNine(); // t.sum(); ninexjiu(); } }
for循环九九乘法表:
public static void ninexnine(int a){ for(int x1=0;x1<=a;x1++){ for(int y1=0;y1<=x1;y1++){ System.out.print(x1+"*"+y1+ "=" +(x1*y1)+"\t"); } System.out.println(); } } public static void main(String[] args){ //TriangleDemo t=new TriangleDemo(); ninexnine(5); } }
累加计算:
public static int sum(int n){ int sum=0; for(int i=0;i<=100;i++){ sum=sum+i; } return sum; // System.out.println("sum="+sum); } public static void main(String[] args){ //TriangleDemo t=new TriangleDemo(); System.out.println("sum="+sum(10)); }
}
标签:long double 名称 main out system 嵌套 return sum
原文地址:https://www.cnblogs.com/hiddenly/p/9343004.html