🌐
CodeAhoy
codeahoy.com › java › Math-Abs-method-JI_12
Java Math.abs() with Examples | CodeAhoy
October 12, 2019 - public class MathEx { public static void main(String[] args) { absolute(); } private static void absolute() { System.out.println(Math.abs(3)); // 3 System.out.println(Math.abs(-3)); // 3 System.out.println(Math.abs(1000L)); // 1000 System.out.println(Math.abs(2.0f)); // 2.0 System.out.println(Math.abs(-2.0f)); // 2.0 System.out.println(Math.abs(-0)); // 0 System.out.println(Math.abs(Double.NEGATIVE_INFINITY)); // + Infinity } } ... There you have it. Hope you found this tutorial useful! For floating-point numbers i.e. float or double: If the argument is positive zero or negative zero, the result is positive zero. If the argument is infinite, the result is positive infinity. If the argument is NaN, the result is NaN. If you need more detailed information, please see Javadocs.
🌐
W3Schools
w3schools.com › java › ref_math_abs.asp
Java Math abs() Method
The abs() method returns the absolute (positive) value of a number. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if ...
Discussions

java - Finding absolute value of a number without using Math.abs() - Stack Overflow
Is there any way to find the absolute value of a number without using the Math.abs() method in java. More on stackoverflow.com
🌐 stackoverflow.com
Absolute value without calling the Math.abs() method?

I think you can probably figure this one out just with a hint.

What happens to negative numbers when they are multiplied by -1?

Note that you can check if numbers are less than zero using if and then do something about less than zero numbers.

If you still get stuck after thinking on that for a few minutes shoot me a pm.

Edit: as long as you don't ask me to just write out all the code for you.

More on reddit.com
🌐 r/javahelp
7
1
December 28, 2015
Should I be using Math.abs?
I'm pretty new to java myself, but doesn't Math.abs return the absolute value, so it returns negative numbers as positive? I'd have gone with else if (18 < age > 24) More on reddit.com
🌐 r/learnjava
4
1
July 28, 2015
Why Math.abs() doesn't work on values that are the MIN_VALUE of the data type?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full - best also formatted as code block You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/learnjava
8
18
July 5, 2022
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Math.html
Math (Java Platform SE 8 )
October 20, 2025 - if the second argument is a finite odd integer, the result is equal to the negative of the result of raising the absolute value of the first argument to the power of the second argument · if the second argument is finite and not an integer, then the result is NaN. If both arguments are integers, then the result is exactly equal to the mathematical result of raising the first argument to the power of the second argument if that result can in fact be represented exactly as a double value.
🌐
Tutorialspoint
tutorialspoint.com › home › java/lang › java math abs() method
Java Math abs() Method
September 1, 2008 - The Java Math abs(int a) returns the absolute value of an int value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned.
🌐
CodeGym
codegym.cc › java blog › java math › java math abs() method
Java Math abs() method
January 9, 2025 - For example, the absolute of +5 is 5. Whereas, the absolute of -5 is also 5. The java.lang.Math class provides a static method Math.abs(parameter) to find the “absolute value” of the parameter.
🌐
Scaler
scaler.com › home › topics › abs() in java
abs() in Java - Scaler Topics
May 5, 2024 - The Math.abs() method is the inbuilt ... Math.abs() method takes one parameter that is of number type and returns its absolute value, i.e. the positive value of the number, without using the negative sign....
🌐
Turing
turing.com › kb › java-absolute-value
Java Math Absolute Value Abs() Method
Similarly, this class has a static method called calculateAbsoluteValue() that takes a double number as input and uses the Math.abs() function to calculate the absolute value. The method returns the absolute value as a double.
Find elsewhere
🌐
Programmers
programmers.io › home › blog › absolute value abs () in java
Absolute Value Abs () In Java - Programmers.io
June 26, 2025 - The Math.abs () method is used in Java development to obtain the absolute value of a number. It belongs to the java.lang.Math class, which is a part of the core Java API.
🌐
Codecademy
codecademy.com › docs › java › math methods › .abs()
Java | Math Methods | .abs() | Codecademy
August 24, 2022 - The Math.abs() method returns the absolute value of the argument. ... Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
🌐
iO Flood
ioflood.com › blog › math-abs-java
Java's Math.abs() Function: Usage Guide with Examples
February 29, 2024 - Whether it’s +10 degrees or -10 degrees, the magnitude of the change is the same: 10 degrees. This is where the absolute value comes in handy. In Java, the Math.abs() function is the built-in method used to calculate the absolute value of a number.
🌐
How to do in Java
howtodoinjava.com › home › java basics › java math.abs() and math.absexact() with examples
Java Math.abs() and Math.absExact() with Examples
January 15, 2024 - Absolute value of double: 10.56 Absolute value of float: 7.8 Absolute value of int: 15 Absolute value of long: 123456789 · While Math.abs() itself does not directly lead to overflow or underflow issues, understanding the behavior of this function is crucial when working with large numeric values, as it may indirectly contribute to such problems.
🌐
Vultr Docs
docs.vultr.com › java › standard-library › java › lang › Math › abs
Java Math abs() - Get Absolute Value | Vultr Docs
December 3, 2024 - The Math.abs() method in Java is a widely used function that returns the absolute value of a given number, effectively removing any negative sign associated with it.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-math-abs-method-examples
Java Math abs() method with Examples - GeeksforGeeks
July 11, 2025 - The java.lang.Math.abs() returns the absolute value of a given argument. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned.
🌐
Medium
medium.com › @n.esmaielyfard › beware-the-trap-using-math-abs-with-random-numbers-in-java-73117b958d1f
Beware the Trap: Using Math.abs() with Random Numbers in Java | by Nariman Esmaiely Fard | Medium
January 23, 2024 - Math.abs() simply returns the absolute value of a given number, stripping away any negative sign. But this technique, when applied to random number generation, requires careful consideration due to the inherent properties of the number range ...
🌐
Educative
educative.io › answers › what-is-the-mathabs-function-in-java
What is the Math.abs function in Java?
In the code above, we use the Math.abs function to find the absolute value of the numbers.
🌐
BeginnersBook
beginnersbook.com › 2022 › 10 › java-math-abs-method
Java Math.abs() Method
October 8, 2022 - public class JavaExample { public static void main(String args[]) { //number divided by zero infinity System.out.println(Math.abs(5.0/0)); //zero divided by zero is NaN (Not a Number) System.out.println(Math.abs(0.0/0.0)); } }
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.lang.math.abs
Math.Abs Method (Java.Lang) | Microsoft Learn
Microsoft makes no warranties, express or implied, with respect to the information provided here. Returns the absolute value of a double value. [Android.Runtime.Register("abs", "(D)D", "")] public static double Abs(double a); [<Android.Runt...