- public class Test {
- public static void main(String[] args) {
- long l = demo(10);
- System.out.println(l);
- }
- public static long demo(int num){
- long sum = 0;
- long temp = 2;
- for(int x = 0;x<num;x++){
- sum+=temp;
- temp = temp*10+2; //2每次乘10再加上2就好了
- }
- return sum;
- }
- }
复制代码 |
|