- class VIP {
- public static void main(String[] args) {
- //方法一:
- /*int sum=0;
- for (int i=0;i<=9 ; i++ ){
- for (int j=i*10+1;j<i*10+11 ;j++ ){
- sum+=j;
- if(j%10==0){
- System.out.print(j);
- break;
- }
- System.out.print(j+"+");
- }
- System.out.print("="+sum);
- System.out.println();
- }*/
- //方法二:最满意方法
- int sum=0;
- for (int i=1;i<=100 ; i++ ){
- sum+=i;
- if(i%10==0){
- System.out.print(i+"="+sum);
- System.out.println();
- }
- System.out.print(i+"+");
- }
- //方法三:
- int sum=0;
- String s="";
- for (int i=1;i<=100 ;i++ ){
- sum+=i;
- if(i%10==0){
- s=i+"=";
- System.out.print(s+sum);
- System.out.println();
- }else{
- s=i+"+";
- }
- }
- }
- }
复制代码 |
|