Skip to content

Instantly share code, notes, and snippets.

@ClearNB
Created January 9, 2019 23:25
Show Gist options
  • Save ClearNB/4559f064af51c376b1f48470105a2dde to your computer and use it in GitHub Desktop.
Save ClearNB/4559f064af51c376b1f48470105a2dde to your computer and use it in GitHub Desktop.
Power digit sum (Java 8 ver) Sample by ClearNB
import java.math.BigInteger;
import java.util.*;
public class Solution {
static int getValue(String data) {
int res = 0;
for(int i = 0; i < data.length(); i++) {
res += Integer.parseInt(data.substring(i, i + 1));
}
return res;
}
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
int T = sc.nextInt();
for(int a0 = 0; a0 < T; a0++) {
int N = sc.nextInt();
BigInteger bi = BigInteger.ONE;
for(int i = 0; i < N; i++) {
bi = bi.multiply(BigInteger.valueOf(2));
}
String str = "" + bi;
int sum = getValue(str);
System.out.println(bi + " : " + sum);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment