Java Program to Find the Sign of Given Number Using Library Method

Java program to find the sign of given number using library method

// Java program to find the sign of a given number 
// using the library method

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner X = new Scanner(;

    double num = 0;

    System.out.print("Enter number: ");
    num = X.nextDouble();

    double res = Math.signum(num);
    if (res == 0)
      System.out.print("Number is zero.");
    else if (res == -1)
      System.out.print("Number is negative.");
    else if (res == 1)
      System.out.print("Number is positive.");
      System.out.print("Number is NaN.");


Enter number: -34
Number is negative
Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment