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);
        }
    
    }

     结果展示:

  • 相关阅读:
    变量1
    PHP 函数
    发送post请求
    XXE
    CSRF
    Html基础
    暴力破解
    Brup sute
    XSS
    URL 传参转义 (特殊符号转义)
  • 原文地址:https://www.cnblogs.com/superdrew/p/8067263.html
Copyright © 2011-2022 走看看