In this we are going to see a basic program to check positive or negative number using ternary operator in Java Programming Language.
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number: ");
int n = sc.nextInt();
String val = (n > 0) ? "Positive" : "Negative";
System.out.println("The number is " + val);
}
}
// Coded by Saahil
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP