write a program to input a number and check whether it is positive, negative or zero using ternary operator
Answers
Answered by
5
Answer:
First we check if a is greater than 0, if its true then the user entered number is positive. If its false, then we check if a is less than 0 using nested ternary / conditional operator. If that is true, then a is negative, else the user entered number is 0.
Answered by
9
Program: {java}
import java.util.*;
public class Brainly
{
static void main()
{
Scanner sc=new Scanner(System.in);
int n;
System.out.print("Enter an integer: ");
n=sc.nextInt();
System.out.println((n>0)?"Positive":(n<0)?"Negative":"Zero");
}
}
Similar questions