write a Java program to input an integer number. Using ternary operator check if the number is even, calculate the square of the number otherwise calculate the cube of the number and print the result.
Answers
Answered by
1
Answer:
import java.util.Scanner;
class even_number {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = scan.nextInt();
int remainder = num % 2;
if(remainder == 0) {
int square = Math.pow(num, 2);
}
else {
int square = Math.pow(num, 3);
}
System.out.println(square);
}
}
Explanation:
Answered by
0
Answer:
javascript is the only way to do that
Similar questions