Showing posts with label positive negative using conditional opeator. Show all posts
Showing posts with label positive negative using conditional opeator. Show all posts

Sunday, June 21, 2020

Write a program to input a number and find the number is Positive, Negative or Neutral using conditional operator.

19)  Write a program to input a number and find the number is Positive, Negative or    Neutral using conditional operator.

import java.util.*;
public class positive_negative_neutral_without_if_5
{
   public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        int a = sc.nextInt();
        String k = (a<0)?"negative":(a>0)?"positive":"neutral";
        System.out.println("Entered number is "+k);
    }
}

 jhvghvgk ;nkjn ,nkjhj