- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java signum() method with Examples
The java.lang.Math.signum(float f) returns the signum function of the argument; zero if the argument is zero, 1.0f if the argument is greater than zero, -1.0f if the argument is less than zero.
Let us now see an example −
Example
import java.security.*; import java.util.*; public class Main { public static void main(String[] argv) { // get two float numbers float x = 50.14f; float y = -4f; // call signum for both floats and print the result System.out.println("Math.signum(" + x + ")=" + Math.signum(x)); System.out.println("Math.signum(" + y + ")=" + Math.signum(y)); } }
Output
Math.signum(50.14)=1.0 Math.signum(-4.0)=-1.0
Let us now see another example −
Example
import java.security.*; import java.util.*; public class Main { public static void main(String[] argv) { double a = 5; double nanVal = Double.NaN; System.out.println(Math.signum(a)); a = -10; System.out.println(Math.signum(a)); a = 0; System.out.println(Math.signum(a)); System.out.println(Math.signum(nanVal)); } }
Output
1.0 -1.0 0.0 NaN
Advertisements