16/03/2023

Positive Negative Program in Java Using IF-ELSE Statements

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.

Positive Negative Program in Java

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

The Output of Positive Negative Program in Java


The Output of Positive Negative Program in Java

Similar to the Positive Negative Program


Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: