Q:

Java Program to check whether the input number is positive or negative

0

Java Program to check whether the input number is positive or negative using if else statement.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Scanner;
public class demo1
{
    public static void main(String[] args) 
    {
        int num;
        Scanner n = new Scanner(System.in);
        System.out.print("Enter the number:");
        num = n.nextInt();
        n.close();
        if(num > 0)
        {
            System.out.println(num+" is positive number");
        }
        else if(num < 0)
        {
            System.out.println(num+" is negative number");
        }
        else
        {
            System.out.println(num+" is neither positive nor negative");
        }
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now