-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTest1.java
More file actions
40 lines (36 loc) · 1.02 KB
/
Copy pathTest1.java
File metadata and controls
40 lines (36 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.sinllychen.string;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Scanner;
/**
* 变成计算i的i次方的和,n为用户输入的任意整数(考虑结果可能超出长整数long的表示范围
* @author sinllychen
*
*/
public class Test1 {
public static void main(String[] args)
{
InputStreamReader reader =new InputStreamReader(System.in);
BufferedReader input=new BufferedReader(reader);
while(true)
{
try{
System.out.print("请输入一个数字(请以输入任意一个字符串结束)");
int n=Integer.parseInt(input.readLine());
/* System.out.println(new BigInteger("234567890").add(new BigInteger("1234567890")));*/
BigInteger sum=new BigInteger("0");
for(int i=1;i<=n;i++)
{
BigInteger a=new BigInteger(String.valueOf(i));
sum=sum.add(a.pow(i));
}
System.out.println("sum="+sum.toString());
}
catch(Exception e)
{
break;
}
}
}
}