Write a javwritea program to input ten numbers. use a function to find and print the square and cube of each number. allow the user to input the number using scanner class.
Answers
Answered by
2
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int []a=new int[10];
int square;
int cube;
for(int i=0;i<a.length;i++)
{
a[i]=sc.nextInt();
}
for(int j=0;j<a.length;j++)
{ int b=a[j];
square=b*b;
cube= b*b*b;
System.out.println("Element= "+a[j]+" Square= "+square+" and Cube= "+cube);
}
}
}
Attachments:
Similar questions
Science,
5 months ago
Math,
5 months ago
Math,
10 months ago
Biology,
10 months ago
Social Sciences,
1 year ago