Monday 5 January 2015

Java Program to check whether a number is Positive Or Negative


This is a simple basic program which checks whether the number is positive or negative.


PROGRAM :


package codingcorner.in;

import java.util.Scanner;

public class PositiveOrNegative {
 public static void main(String[] args) {
  float a;
  Scanner scan = new Scanner(System.in);

  System.out.println("Enter any number :\n");
  a = scan.nextFloat();

  scan.close();

  if (a == 0)
   System.out.println(a + " is neither positive nor negative");
  else if (a > 0)
   System.out.println(a + " is a Positive number");
  else
   System.out.println(a + " is a Negative number");
 }
}
 
OUTPUT :





No comments:

Post a Comment