Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
0
try: public class Digit { public static void main(String[] args) { int n=153; // int number to separate in single digit double sum=0; do{ int i; i=n%10; n=n/10; sum=sum+ Math.pow(i,3); } while (n>10); System.out.println(n+" "+sum); } } the loop extracts the last digit of the number and puts it in the variable, then divide the number by 10 and added to the variable sum the cubes of i
29th Nov 2016, 2:10 PM
Simone Novaro
Simone Novaro - avatar