zoukankan      html  css  js  c++  java
  • 求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个数字。

    package studying;
    
    import java.util.Scanner;
    
    //题目:求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个数字。  
    //例如2+22+222+2222+22222(此时共有5个数相加),几个数相加有键盘控制。 
    
    public class Chengxu8 {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Scanner input = new Scanner(System.in);
            
            int sum = 0;
            int temp = 0;
            System.out.println("the question is:求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个数字。");
            System.out.println("Which number of loops to use:(a)");
            int a = input.nextInt();
            System.out.println("Loop several times:");
            int b = input.nextInt();
            
            for(int i = 0; i < b; i++) {
                temp = temp * 10 + a;
                System.out.println("The "+ (i+1) +" number is:" + temp);
                sum += temp;
            }
            System.out.println("The results of the calculation are:"+sum);
        }
    
    }

     结果展示:

  • 相关阅读:
    java.lang.NoSuchMethodError:antlr.collections.AST.getLine() I
    T7 java Web day01 标签HTML
    T6 s1 day19
    T5 s5 Day18
    T5 s4 Day 17
    T5 s3 day16
    T5 s2 Day 15
    T5 s1 day14
    T4 S03 day 12
    T4 S01 day1
  • 原文地址:https://www.cnblogs.com/superdrew/p/8067263.html
Copyright © 2011-2022 走看看