Java program to identify whether the number is positive or negative (By user input).

 1. Write a program in Java to print whether the number is positive or negative as per the input given by the user.

Code

import java.util.Scanner;

public class Numberpositiveornegative {
    public static void main(String args[]){
        Scanner a = new Scanner(System.in);
        System.out.println("Enter the Number");
        int Num = a.nextInt(); 
        if(0>Num){
            System.out.println("Number is Negative");
        }
        else
        System.out.println("Number is Positive");

    }
    
}

Output

Enter the Number

-5

Number is Negative

Post a Comment

0 Comments