Java Program to Check Whether a Number is EvenorOdd
Check if a Number is Positive or Negative in Java
Given an integer input, The objective is to write a code to Check if a Number is Positive or Negative in Java Language.
For Instance,Input : Num = -5
Output : The number is Negative
For a user input num
If the num > 0: it is a positive number.
If the num < 0: it is a positive number.
Else the number has to be zero itself
public static void main (Stringargs)
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number: ");
int num = sc.nextInt();
//Conditions to check if the number is negative or positive
if (num > 0)
System.out.println ("The number is positive");
else if (num < 0)
System.out.println ("The number is negative");
Enter a number: 22
The number is Positive