Java program that reads a floating ­point number and prints zero if the number is zero. Otherwise, print positive or negative
Posted by Samath
Last Updated: February 11, 2021
  1366

Write a Java program that reads a floating­point number and prints zero if the number is zero. Otherwise, print positive or negative. Add small if the absolute value of the number is less than 1, or large if it exceeds 1,000,000.

Code:

import java.util.Scanner;

public class Main
{
	public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter Number: ");
        double number = input.nextDouble();
        input.close();
        System.out.print((number > 0)? 
                             (number < 1)? "Positive small":
                             (number > 1000000)? "Positive large":
                             "Positive":
                         (number < 0)? 
                             (number < 1)? "Negative small":    
                             (number > 1000000)? "Negative large":
                             "Negative":
                         "Zero");
    }
}