Saturday, 24 December 2016

Java Program To Check Number Is Positive Or Negative

Problem :- Write A Java Program To Check Number Is Positive Or Negative .Number should be Entered Through User Then program Print the Output .

Logic :- As we know that if number is greater than 0 ( Zero ) Than number is positive and if number is Less than 0 ( Zero ) than number is Negative and else number is equal to zero than entered number is Zero .

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

Solution :- 

import java.util.Scanner;
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:-


Java Program To Check Number Is Positive Or Negative

No comments:
Write comments

Recommended Posts × +