Q:

Write a Java program to display the cube of the number upto given an integer

0

Write a Java program to display the cube of the number upto given an integer

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..

import java.util.Scanner;
public class JavaExcercise {
 
   public static void main(String[] args)
 
{
    int i,n;
 
    System.out.print("Enter number of terms : ");
    Scanner num = new Scanner(System.in);
            n = num.nextInt();
 
     for(i=1;i<=n;i++)
     {
     System.out.println( "cube of " +i+" is : "+(i*i*i));     
    }
 }
}

Result:

Enter number of terms : 6

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

cube of 6 is : 216

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a Java program to display the n terms of odd... >>
<< Write a java program to check vowel or consonant...