import java.util.Scanner;
public class DisplayCubeUptoN
{
public static void main(String[] args)
{
// declare here
int n,i;
// enter number upto which you have to find cube.
System.out.print("Enter the last number for cube : ");
Scanner Sc= new Scanner(System.in);
// scan the number and store it variable.
n = Sc.nextInt();
// loop to find cube for all possile numbers.
for(i=1;i<=n;i++)
{
System.out.println("Cube of " +i+" is : "+(i*i*i));
}
}
}
Output
Enter the last number for cube : 5
Cube of 1 is : 1
Cube of 2 is : 8
Cube of 3 is : 27
Cube of 4 is : 64
Cube of 5 is : 125
Program to find cube from 1 to N in java
Output
need an explanation for this answer? contact us directly to get an explanation for this answer