Positive Negative Program in Java. Write a Java Program to Get a Number From The User And Print Whether it is Positive or Negative. Checking whether a Number is a positive or negative number should be entered through the user then the program print the output.
As we know that if the number is greater than 0 (Zero) Then the number is positive and if the number is Less than 0 (Zero) that number is Negative and if else number is equal to zero then an entered number is Zero.
Positive Negative Program in Java
import java.util.Scanner;
import java.io.*;
/* Positive Negative Program in Java */
public class Posi_Negative {
public static void main(String[] args) {
int number;
Scanner scan = new Scanner(System.in);
System.out.print("Enter The Number You Want to Check:");
number = scan.nextInt();
if (number > 0) {
System.out.println("The Number Is " + number + " is Positive");
} else if (number < 0) {
System.out.println("The Number Is " + number + " is Negative");
} else {
System.out.println("The Number Is " + number + " is Zero ");
}
}
}
See Also: C Program To Check Number Is Positive Or Negative
0 Comments: