在控制台输出以下字样:
1+2+3+4+5+6+7+8+9+10 = 55
11+12+13+14+15+16+17+18+19+20 = (算不出来了...)
21+22+........30 = ..
......
....
91+92+93+....100 = ..
两种方法:
1,
class Day05 {
public static void main(String[] args) {
int sum = 0;
for (int x = 1;x <= 100 ;x++ ) {
sum +=x;
if (x%10 !=0 ) {
System.out.print(x+"+");
}
else {
System.out.println(x+"="+sum);
sum = 0;
}
}
}
}
2,
class Day05 {
public static void main(String [] args) {
for (int i = 1;i <= 100; i +=10) {
int sum = 0;
int j;
for (j = 0;j <= 8; j++) {
System.out.print(j+i + "+");
sum += j+i;
}
System.out.println(j+i + "=" + (sum+j+i));
}
}
}
|
|