Created
January 29, 2015 14:04
-
-
Save shohan4556/6c5c12edc9e14cd5c221 to your computer and use it in GitHub Desktop.
project euler 16 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]; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment