Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
Sum of power of digits-1
//'main' method must be in a class 'Rextester'. //openjdk version '11.0.5' class Rextester { public static void main(String args[]) { int x=582109; int power; int sum=1; String s=Integer.toString(x); System.out.println(s); char a[]=s.toCharArray(); for(int i=0;i<a.length;i++) { System.out.println(a[i]); } for(int i=1;i<a.length;i++) { int dig=Character.getNumericValue(a[i-1]); int exp=Character.getNumericValue(a[i]); power=(int)(Math.pow(dig,exp)); sum+=power; } System.out.println("Sum of power= "+sum); } }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Java 8... lambda, streams und so...
exp 4
piglatin
4pr
1(E)
Sqrt
1a
Length of longest substring
Strings Ops
find Kth largest element in array
Please log in to post a comment.