write a program to find out whether a number is negative or not Java program
Answers
Answer:
public class Program1
{
public void main (int num)
{
if (num<0)
{
System.out.println("Negative number");
}
else
{
System.out.println("Not negative number");
}
}
}
Answer: Java Program to Check if a Given Integer is Positive or Negative
Explanation:
This is a Java Program to Check if a Given Integer is Positive or Negative.
Enter any integer number as an input. Now we check whether the given number is greater than zero or not. If the given number is greater than zero than it is positve. If it is less than zero than it is negative and if it is zero than it is neither poistive nor negative.
Here is the source code of the Java Program to Check if a Given Integer is Positive or Negative. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
import java.util.Scanner;
public class Postive_Negative
{
public static void main(String[] args)
{
int n;
Scanner s = new Scanner(System.in);
System.out.print("Enter the number you want to check:");
n = s.nextInt();
if(n > 0)
{
System.out.println("The given number "+n+" is Positive");
}
else if(n < 0)
{
System.out.println("The given number "+n+" is Negative");
}
else
{
System.out.println("The given number "+n+" is neither Positive nor Negative ");
}
}
}
Output:
$ javac Postive_Negative.java
$ java Postive_Negative
Enter the number you want to check:6
The given number 6 is Positive