Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
Long signum() Method in Java
Next article icon

Long signum() Method in Java

Last Updated : 05 Dec, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report
The signum function also known as sign function is an odd mathematical function that extracts the sign of a real number. The java.lang.Long.signum() method is used to get the signum function of the specified long value. For a positive value, a negative value and zero, the method returns 1, -1 and 0 respectively. Syntax :
public static int signum(long num)
Parameters: The method accepts one parameter num of long type on which the signum operation is to be performed. Return Value: The method returns the signum function of the specified long value. If the specified value is:
  • Negative, the method returns -1.
  • Zero, the method returns 0.
  • Positive, the method returns 1.
Examples:
  Input: (Long) 2731766  Output: 1    Input: (Long) -233611   Output: -1    Input: (Long) 0  Output: 0  
Below programs illustrate the Java.lang.Long.signum() Method: Program 1: java
// Java program to illustrate the // Java.lang.Long.signum() Method import java.lang.*;  public class Geeks {      public static void main(String[] args)     {          // It will return 1 as long value is greater than 1         System.out.println(Long.signum(36565531));          // It will return -1 as long value is less than 1         System.out.println(Long.signum(-628127));          // Returns 0 as long value is equal to 0         System.out.println(Long.signum(0));     } } 
Output:
  1  -1  0  
Program 2: For decimal value and string. java
// Java program to illustrate the // Java.lang.Long.signum() Method import java.lang.*;  public class Geeks {      public static void main(String[] args)     {          // It will return compile time error         System.out.println(Long.signum(36565.531));          // It will return compile time error         System.out.println(Long.signum("628127"));     } } 
Output:
    prog.java:10: error: incompatible types: possible lossy conversion from double to long      System.out.println(Long.signum(36565.531));                                     ^  prog.java:13: error: incompatible types: String cannot be converted to long      System.out.println(Long.signum("628127"));                                     ^  Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output  2 errors  

Next Article
Long signum() Method in Java

A

ankita_chowrasia
Improve
Article Tags :
  • Java
  • Java-lang package
  • Java-Functions
  • java-Long
Practice Tags :
  • Java

Similar Reads

    Integer signum() Method in Java
    The signum function is an odd mathematical function that extracts the sign of a real number. The signum function is also known as sign function. The Integer.signum() method of java.lang returns the signum function of the specified integer value. For a positive value, a negative value and zero the me
    3 min read
    Month length() method in Java
    The length() method is a built-in method of the Month ENUM which is used to get the number of days in this month instance. The number of days in a month can be 28, 30 or 31. Number of days in February in a leap year is 29. This method accepts a boolean flag variable which indicates whether this Year
    1 min read
    LongStream sum() in Java
    LongStream sum() returns the sum of elements in this stream. This is a special case of a reduction. LongStream sum() is a terminal operation i.e, it may traverse the stream to produce a result or a side-effect. Note : A reduction operation (also called a fold) takes a sequence of input elements and
    2 min read
    Month maxLength() method in Java
    The maxLength() method is a built-in method of the Month ENUM which is used to get the maximum length of this month in number of days. For example, February can have both 28 days and 29 days depending on whether this year is a leap year or not. Therefore, this method will return 29 for February as m
    1 min read
    Long longValue() Method in Java
    The java.lang.Long.longValue() is an inbuilt method of the Long class in Java which returns the value of this Long object as a long after the conversion.Syntax: public long longValue() Parameters: This method does not take any parameters.Return Value: This method will return the numeric value repres
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences