Pessoal eu tenho que fazer um programa que mostre a potencia de 2 elevado a milesima potencia e depois somar seus carateres(numeros) e dar a soma.
Eu fiz este codigo mas não ta dando certo.
import java.math.BigInteger;
import java.util.Scanner;
import java.io.File;
import java.io.*;
public class scan{
public static void main(String args[]){
BigInteger bi = new BigInteger("2");
BigInteger soma = BigInteger.ZERO;
try{
FileWriter file = new FileWriter("C:\\Renato.txt");
PrintWriter out = new PrintWriter(file);
out.println(bi.pow(1000));
out.close();
Scanner scan = new Scanner(new File("C:\\Renato.txt"));
while(scan.hasNextBigInteger()){
BigInteger i = scan.nextBigInteger();
soma = soma.add(i);
}
scan.close();
System.out.println(soma);
}catch(Exception e){
e.printStackTrace();
}
}
}
Eu teria que fazer desse jeito:
215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
Como posso corrigir isso?
grato.