16) Problem 16- Project Euler Solution in Java
215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 21000?
Using the BigInteger() class :
int sum =0;
BigInteger big = new BigInteger("2");
big = big.pow(1000);
String result =big.toString();
for(int i=0;i<result.length();i++){
sum+=Character.getNumericValue(result.charAt(i));
}
System.out.println("sum : "+sum );
What is the sum of the digits of the number 21000?
Using the BigInteger() class :
int sum =0;
BigInteger big = new BigInteger("2");
big = big.pow(1000);
String result =big.toString();
for(int i=0;i<result.length();i++){
sum+=Character.getNumericValue(result.charAt(i));
}
System.out.println("sum : "+sum );
Comments
Post a Comment