Fare丶梦


私信TA

用户名:126913199

访问量:41123

签 名:

等  级
排  名 236
经  验 6119
参赛次数 0
文章发表 50
年  龄 22
在职情况 学生
学  校
专  业

  自我简介:

TA的其他文章


//普通方法

import java.util.Scanner;


public class Main {

        public static void n(int num){

                int Sn = 0;

                int sum = 1;

                int M=0;

                for(int i = 0;i<num;i++){

                        if(i!=0){

                                sum = sum*10;

                                Sn = Sn+2*sum;

                                M+=Sn;

                        }else{

                                Sn = Sn+2;

                                M+=Sn;

                        }

              }

              System.out.print(M);

        }


        public static void main(String[] arg){

                Scanner sc = new Scanner(System.in);

                int num = sc.nextInt();

                n(num);

        }

}



//API方法

import java.util.Scanner;


public class Main {

        public static void n(int num){

                int Sn = 0;

                int M=0;

                for(int i=0;i<num;i++ ){

                        Sn = (int) (Sn +2*Math.pow(10, i));

                        M+=Sn;

                }

                System.out.print(M);

        }

        public static void main(String[] arg){

                Scanner sc = new Scanner(System.in);

                int num = sc.nextInt();

                n(num);

        }

}


 

0.0分

2 人评分

  评论区

很厉害,我一直想找个包来取为 计算机就是数学,真没错 哎 作者很棒
2017-12-09 17:28:17
  • «
  • 1
  • »