Problem : 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?
Solution :
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package projecteuler; // replace | |
import java.math.BigInteger; | |
/** | |
* | |
* @author Shohan | |
*/ | |
public class euler16 { | |
public static void main(String args[]){ | |
long ans=0; // 64 bit data type in java | |
char[] ara=new char[1000]; // create an array with 1000 index | |
BigInteger num=new BigInteger("2"); // created BigInteger type obj named "num" | |
int pow=1000; | |
ara=num.pow(pow).toString().toCharArray(); // calculate the power of the | |
// "toString()" method is used to represent an object into a String | |
// "toCharArray()" method can be used to convert a String to an array of Character | |
for(int i=0;i<ara.length;i++){ | |
ans=ans+ara[i]-'0'; | |
// System.out.print(ara[i]+" "); | |
} | |
System.out.println(" Sum of 2^1000 is : "+ans); | |
int b[]=new int[10]; | |
} | |
} |