Showing posts with label positivenegative. Show all posts
Showing posts with label positivenegative. 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);
    }
}

Thursday, June 4, 2020

Write a program in java to input a number and check whether it is Positive or Negative or Neutral?

4)  Write a program in java to input a number and check whether it is Positive or Negative or Neutral?

public class positive_negative_neutral
{
   public static void main(int a)
   {
       if(a>0)
       {
           System.out.println("positive");
       }
       else if(a<0)
       {
           System.out.println("Negative");
       }
       else if(a==0)
       {
           System.out.println("Neutral");
        }
    }
}

 jhvghvgk ;nkjn ,nkjhj