write a java program to print square and cube of any user given number using method ((void square( int n), void cube( int n))
Answers
Answered by
5
import java.util.*;
class Number
{
public void square(int n)
{
System.out.println("Square of "+n +(n*n));
}
public void cube(int n)
{
System.out.println("Cube of "+n+ (n*n*n));
}
public static void main()
{
Scanner sc=new Scanner(System.in);
Number ob=new Number();
System.out.println("Enter your number");
int a=sc.nextInt();
ob.square(a); // call square function
ob.cube(a); // to call cube function
}
}
Hope it will help you@ Priya
For more java doubts follow me
class Number
{
public void square(int n)
{
System.out.println("Square of "+n +(n*n));
}
public void cube(int n)
{
System.out.println("Cube of "+n+ (n*n*n));
}
public static void main()
{
Scanner sc=new Scanner(System.in);
Number ob=new Number();
System.out.println("Enter your number");
int a=sc.nextInt();
ob.square(a); // call square function
ob.cube(a); // to call cube function
}
}
Hope it will help you@ Priya
For more java doubts follow me
amannishad0512p5zxh6:
Takki input le sakke
Similar questions
Math,
6 months ago
Social Sciences,
6 months ago
Social Sciences,
1 year ago
Math,
1 year ago
Physics,
1 year ago