12/24/2016

Java Program to Find Number Is Positive or Negative

Problem :- Java Program To Find Number Is Positive Or Negative or Java Program to Check if a Given Integer is Positive or Negative or Java Program to check if Number is Positive or Negative or Java program to find Positive or Negative Number or Java Program to Count Positive, Zero, and Negative Numbers or How to check if a Number is Positive or Negative in Java or Java Program To Check Whether Number Is Positive Or Negative. Write A Java Program To Check Number Is Positive Or Negative.


Logic:- Checking Number is positive or negative number should be entered through user then program print the output. As we know that if the number is greater than 0 ( Zero ) Than number is positive and if the number is Less than 0 ( Zero ) that number is Negative and else number is equal to zero than an entered number is Zero.


See Also:- C++ Program To Check Number Is Positive Or Negative


Java Program to Find Number Is Positive or Negative


import java.util.Scanner;
import java.io.*;
/* Program By Ghanendra Yadav
   Visit http://www.programmingwithbasics.com
*/
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

Output:-



No comments:

Post a Comment