Distinguish between positive and negative numbers in Java

Use the signum method of the Math class

Mathsignum.java


//Returns in double type.
//1 if positive.0, 0 if 0.0, if it is a negative number-1.Returns 0.
System.out.print(Math.signum(10)); // 1.0
System.out.print(Math.signum(0)); // 0.0
System.out.print(Math.signum(-10)); // -1.0

Math class

The Math class contains methods for performing basic numerical operations such as exponential, logarithmic, square root, and trigonometric functions.

It seems.

signum method

Returns the sign element of the argument. Zero if the argument is zero, 1.0 if the argument is greater than zero, -1.0 if the argument is less than zero.

The wording is slightly different, but it is as stated in the comment out above.

reference

Class Math signum method | Introduction to Java code

Recommended Posts

Distinguish between positive and negative numbers in Java
Difference between final and Immutable in Java
Difference between int and Integer in Java
Difference between next () and nextLine () in Java Scanner
[Java] Difference between static final and final in member variables
[Java] Difference between == and equals
Calculate prime numbers in Java
Think about the differences between functions and methods (in Java)
Differences in how to handle strings between Java and Perl
Is short-circuit evaluation really fast? Difference between && and & in Java
Differences between "beginner" Java and Kotlin
[Java] Difference between Hashmap and HashTable
Encoding and Decoding example in Java
StringBuffer and StringBuilder Class in Java
[JAVA] Difference between abstract and interface
[Java] Relationship between H2DB and JDBC
[Java] Difference between array and ArrayList
Understanding equals and hashCode in Java
Differences between Java and .NET Framework
[Java] Difference between Closeable and AutoCloseable
[Java] Difference between StringBuffer and StringBuilder
[Java] Difference between length, length () and size ()
Hello world in Java and Gradle
After switching between Java 8 and 11 versions, an error occurs in confirmation
Conversion between Kotlin nullable and Java Optional
A note on the differences between interfaces and abstract classes in Java
Difference between pop () and peek () in stack
[Java] for Each and sorted in Lambda
[For beginners] Difference between Java and Kotlin
Distinguish between runtime and compile time polymorphism
[Java] Differences between instance variables and class variables
[Note] Cooperation between Java and DB (basic)
Difference between getText () and getAttribute () in Selenium
Difference between "|| =" and "instance_variable_defined?" In Ruby memoization
Arrylist and linked list difference in java
Difference between EMPTY_ELEMENTDATA and DEFAULTCAPACITY_EMPTY_ELEMENTDATA in ArrayList
Find the maximum and minimum of the five numbers you entered in Java
Program PDF headers and footers in Java
[Java] Difference between Intstream range and rangeClosed
Understand the difference between int and Integer and BigInteger in java and float and double
Learn Flyweight patterns and ConcurrentHashMap in Java
Java Direction in C ++ Design and Evolution
Java to C and C to Java in Android Studio
Reading and writing gzip files in Java
Discrimination of Enums in Java 7 and above
HashMap # putAll () behaves differently between Java 7 and Java 8
[Java] Difference between equals and == in a character string that is a reference type
Organize your own differences in writing comfort between Java lambda expressions and Kotlin lambda expressions.
[Java] Understand the difference between List and Set
Create barcodes and QR codes in Java PDF
Detect similar videos in Java and OpenCV rev.2
Parallel and parallel processing in various languages (Java edition)
Generate normal distribution / lognormal distribution random numbers in Java
[Understanding] Differences between hashes and arrays in Ruby
Differences in writing Java, C # and Javascript classes
Capture and save from selenium installation in Java
Detect similar videos in Java and OpenCV rev.3
[Java] Understand in 10 minutes! Associative array and HashMap
Basics of threads and Callable in Java [Beginner]
Summarize the differences between C # and Java writing
Java adds and removes watermarks in word documents