Computer Science, asked by aratrika79, 1 year ago

Write a program to accept a number. If the number is positive display its square.If the number is negative display its cube.USE SCANNER CLASS

Answers

Answered by parna8
1
int a,n;
if a greater than 0
n = a*a;
else
n=a*a*a

aratrika79: import java.util.*;
public class PositiveNegative
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
int a,n;
if(a>0)
n=a*a;
else
n=(a*a*a);
}
}
aratrika79: what's the problem in this program.
Answered by llMissHaseenall
0

Answer:

n=a*a*a is your answer

hope it helpfull

Similar questions