coding Java
bisa ambil coding java di sini untuk latihan project-project java :
contohnya : mencari 2 ^ 1000
** *Author : Vlad *Website: www.mycoding.net *Answer: 1366 */ import java.math.BigInteger; public class Euler16 { public static void main(String[] args) { int power = 1; BigInteger expo = new BigInteger("2"); BigInteger num = new BigInteger("2"); while(power < 1000){ expo = expo.multiply(num); power++; } System.out.println(expo); //Printing the value of 2^1000 int sum = 0; char[] expoarr = expo.toString().toCharArray(); int max_count = expoarr.length; int count = 0; while(count<max_count){ //While loop to calculate the sum of digits sum = sum + (expoarr[count]-48); count++; } System.out.println(sum); } }
Komentar
Posting Komentar