Computer Science, asked by singhanjanapalak, 11 months ago

wap in java to input 10 numbers. use a function to find and print the cube of each number.

Answers

Answered by franktheruler
2

import java.util.*;

class Cube

{

   int i, c ;

   public void Cube_ calculation ( )

    {

       scanner sc = new scanner (  system . in ); // sc is an object of       scanner class

       for( i=0 ; i < 11 ; i++ )

        {

           System. Out. println ( " enter number " ) ;

           c = sc. nextInt ( ) ;

           System.out.println (" cube of a number is :" + ( c * c * c ) ;

       }

   }

class Main_class

{

   public static void main(String args[ ] )

     {

        Cube A = new Cube ( ); // create an object of class Cube

        A . Cube_calculation ( ) ;  

     }

}

Explanation :

Cube of a number means a number multiplied by itself 3 times.

cube of 3 = 3 * 3 * 3 = 27

in java program, a scanner is used for taking input from the user.

system.in.println is used to print any message.

c = nextInt ( ) is used to input the value of an integer variable ' c ' from user.

the new keyword is used for creating an object of the existing class.

And the public is an access specifier.

Similar questions