write a program in java to input 10 numbers. Use a function to find and print the cube of each number
Answers
Answered by
9
The given code accepts 10 numbers from the user and stored into array. Then it find the cubes of the input numbers and display it on console.
import java.util.*; class CubeOfNumbers{ public static void findCube(int num[]){ for(int i=0;i<num.length;i++){ System.out.println("Cube of "+num[i]+" is: "+(num[i]*num[i]*num[i])); } } public static void main(String args[]){ Scanner input=new Scanner(System.in); int array[]=new int[10]; for(int i=0;i<array.length;i++){ array[i]=input.nextInt(); } findCube(array); } }
import java.util.*; class CubeOfNumbers{ public static void findCube(int num[]){ for(int i=0;i<num.length;i++){ System.out.println("Cube of "+num[i]+" is: "+(num[i]*num[i]*num[i])); } } public static void main(String args[]){ Scanner input=new Scanner(System.in); int array[]=new int[10]; for(int i=0;i<array.length;i++){ array[i]=input.nextInt(); } findCube(array); } }
Similar questions