Java program that reads an integer and prints if it's positive or negative
Posted by Samath
Last Updated: February 11, 2021

Write a java program that reads an integer and prints if it's positive or negative.

Code:

import java.util.Scanner;

public class Main
{
	public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int number;
        
        System.out.print("Enter Number: ");
        number = input.nextInt();
        input.close();
        
        System.out.println((number > 0)?  "Positive":
                           (number == 0)? "Zero":
                                          "Negative");
    }
}
Related Content