Create a java program to determine what integers of two, three, and four digits are equal to the sum of the cubes of their digits?

Code :

import java.util.*;
import java.io.*;
class Cubesum {
public static void main(String args[]){
int input=0;
int num1,num2,num3;
//read the number
System.out.print("Enter a positive integer: ");
Scanner console = new Scanner(System.in);
input= Integer.parseInt(console.nextLine());
int number = input; //number is a temp variable
int counter = 0; //counter is used to count no of digits
while(number>0){
int t= number%10;
counter += t * t * t;
number = number/10;
}
System.out.println("The sum of the cubes of the digits is: "+counter);
}
}

Output:

Enter a positive integer: **223**

The sum of the cubes of the digits is: 43

I want to get this output from the program:

371 = 3³+7³+1³

How would I do it?

Re: Create a java program to determine what integers of two, three, and four digits are equal to the sum of the cubes of their digits?

You have the wrong formula.

Hint: you need to use the math class.

Another hint: Math.pow(num1, 3) //example

Re: Create a java program to determine what integers of two, three, and four digits are equal to the sum of the cubes of their digits?

Formula is quite all right. This code sample calculates sum of cubes of digits for a single number.

Now you need simply enclose this calculation in a loop which iterates "number" from 10 to 9999 and print only those numbers for which "counter" equals to "number".