两种方法:
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));
}
}
}