🌐
GeeksforGeeks
geeksforgeeks.org › java › java-math-class
Java Math Class - GeeksforGeeks
July 23, 2025 - ... // Java program to demonstrate ... MathLibraryExample { public static void main(String[] args) { int i = 7; int j = -9; double x = 72.3; double y = 0.34; System.out.println("i is " + i); System.out.println("j is " + j); // The absolute ...
🌐
W3Schools
w3schools.com › java › java_ref_math.asp
Java Math Methods
Arrays Loop Through an Array Real-Life Examples Multidimensional Arrays Code Challenge · Java Methods Java Method Challenge Java Method Parameters · Parameters Return Values Code Challenge Java Method Overloading Java Scope Java Recursion · Java OOP Java Classes/Objects Java Class Attributes ...
Discussions

Math Class, Methods, and random Numbers (Java) - Stack Overflow
I am in desperate need for help with a Java Program I need to compete for school! I have been working on this for at least 3 hours for the past 3 days and I can not figure it out.... =( Here are the directions: Write a program that calls each of the methods of the Math class from the list below and provides output showing the method called, values sent to the method, and the returned results. Each listed method will tell you which values to use. For example... More on stackoverflow.com
🌐 stackoverflow.com
Using Math in Java
I have tried normal tan and atan but they didn't seem to work/output the correct variable. Math.atan is the correct method, but you need to be aware that Java (as most programming languages) calculates in radians, not in degrees. Still, there is Math.toDegrees that converts the value from radians to degrees. The opposite is Math.toRadians More on reddit.com
🌐 r/javahelp
6
3
October 17, 2018
Difference Between Java Integer Class Methods and Java Math Class Methods?
Why are Math Class methods called with 'Math.abs()', but Integer Class methods are called with 'static int sum()' or 'int min()'? I think you are confusing some things here. The examples you show for the integer methods are method definitions. That's not calling a method, it's defining one that returns an int. Doesn't the Math Class have max & min methods? So why does the Integer Class also have max and min methods? The Math.max and Math.min methods have overloads for integers, longs, floats, and doubles. But each of those classes have a specific version of the function that just works on its own. It's likely that the Math class is just "proxying" those other methods, based on what you pass into it. It's just there as a convenience, so you don't have to dip down into four different classes for the same functionality. More on reddit.com
🌐 r/learnprogramming
2
1
February 23, 2022
How precise is Java's Math class?
The key thing to note is that BigDecimal is decimal. That is, it stores a precise representation of decimal (base-10) numbers. That is, the number is represented as a sum of powers of ten. float and double are binary (IEEE 754). That is, the number is represented as a sum of powers of two. Thus, when you translate a decimal fraction into a binary fraction, you'll end up with errors, because some decimal fractions cannot be represented exactly as binary fractions (within a given precision). These errors add up. The Math functions are intrinsics. They map directly to native routines, which operate on IEEE 754 floating point numbers. Obviously, most floating point units on processors work on IEEE floats (although, I think some older processors could do BCD math). BigDecimal is implemented purely in Java, trading performance for precision, and any math library operating on BigDecimal would have to reimplement all of those math operations in Java, similarly trading performance for precision, to a greater degree. Whether you choose float of BigDecimal depends on your goals. With money, generally the goal is precision, because of the financial consequences of errors in accounting calculations. But, in scientific and engineering application, the goal is reasonable approximation within an error range. I don't think with Black-Sholes you're looking for precision, but approximation. Thus, it is perfectly fine to use float as long as you arrange your calculations to control the error range. Poor arrangement of floating point calculations can significantly widen the error range, resulting wildly deviating results. For this reason, there are books like Numerical Computing with IEEE Floating Point Arithmetic which show you how to arrange floating point calculations to maintain accuracy within a desired error range. EDITED: I don't write good. More on reddit.com
🌐 r/java
84
68
June 16, 2024
🌐
Tutorialspoint
tutorialspoint.com › java › java_lang_math.htm
Java - Math Class
package com.tutorialspoint; public class MathDemo { public static void main(String[] args) { // get two double numbers double x = 60984.1; double y = -497.99; // get the natural logarithm for x System.out.println("Math.log(" + x + ")=" + Math.log(x)); // get the natural logarithm for y System.out.println("Math.log(" + y + ")=" + Math.log(y)); // get the max value System.out.println("Math.max(" + x + ", y" + ")=" + Math.max(x,y)); // get the min value System.out.println("Math.min(" + x + ", y" + ")=" + Math.min(x,y)); } }
🌐
W3Schools
w3schools.com › java › java_math.asp
Java Math
assert abstract boolean break byte case catch char class continue default do double else enum exports extends final finally float for if implements import instanceof int interface long module native new package private protected public return requires short static super switch synchronized this throw throws transient try var void volatile while Java String Methods
🌐
iO Flood
ioflood.com › blog › math-class-java
Exploring Java's Math Class: Methods and Examples
February 29, 2024 - In this example, we use the sqrt() method from the Math class to calculate the square root of 16. The result is then printed to the console, giving us an output of 4.0. The Math class in Java adheres to the IEEE 754 standard for floating-point ...
🌐
Tpoint Tech
tpointtech.com › java-math
Java Math Class (Methods with Examples) - Tpoint Tech
March 17, 2025 - The following example demonstrates basic mathematical operations such as maximum, square root, power, and logarithmic calculations using the Math class. ... Maximum number of x and y is: 28.0 Square root of y is: 2.0 Power of x and y is: 614656.0 Logarithm of x is: 3.332204510175204 Logarithm ...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Math.html
Math (Java Platform SE 8 )
October 20, 2025 - Java™ Platform Standard Ed. 8 ... The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions.
🌐
FavTutor
favtutor.com › blogs › java-math-class
Math Class in Java & Methods (with Examples)
October 9, 2023 - Since the Math class is part of the java.lang package, it is automatically accessible in every Java program. This means that you can directly use the methods and constants of the Math class without importing it explicitly. For example, you can use the Math.PI constant to access the value of pi or the Math.sqrt() method to calculate square roots.
Find elsewhere
🌐
Jenkov
jenkov.com › tutorials › java › math-operators-and-math-class.html
Java Math Operators and Math Class
Here are a few Java Math.sqrt() example: double sqrt4 = Math.sqrt(4); System.out.println("sqrt4 = " + sqrt4); double sqrt9 = Math.sqrt(9); System.out.println("sqrt9 = " + sqrt9); The output printed from these Java Math.sqrt() examples would ...
🌐
IONOS
ionos.com › digital guide › websites › web development › how to use java math class
How to use the Java Math class - IONOS
July 18, 2024 - Below, we’ve included a range of different cal­cu­la­tions to show you how the class works. If you want to determine the absolute value of a parameter, you can use abs(). An absolute value is the distance between a number and 0 or an unsigned number. This means the result will always be positive. The data types permitted for this method are double, float, int and long. Below, we’ll show you how Math.abs works with a positive number. For the output in the examples that follow, we’ll use the Java command System.out.println.
🌐
Javatpoint
javatpoint.com › java-math
Java Math Class
Java Math class with methods with Examples on abs(), min(), max(), avg(), round(), ceil(), floor(), pow(), sqrt(), sin(), cos(), tan(), exp() etc.
🌐
Oxford University
mathcenter.oxford.emory.edu › site › cs170 › mathClass
Commonly Used Methods of the Math Class
The operators +, -, *, /, and % give us a way to add, subtract, multiply, divide, and "mod" values together in java, but having to implement some of the more sophisticated functions of mathematics (like the square root or sine functions) with only these operators would be challenging indeed!
🌐
Edureka
edureka.co › blog › java-math-class
Math Class in Java | Java.lang.Math Class and Methods | Edureka
August 28, 2019 - This article will help you with a Comprehensive approach towards Math Class in Java along with Practical examples for better understanding of the concept.
🌐
GeeksforGeeks
geeksforgeeks.org › java › math-class-methods-java-examples-set-2
Math class methods in Java with Examples | Set 2 - GeeksforGeeks
July 23, 2025 - Floor value of f1 : 30.0 Floor value of f2 : -57.0 Hypotenuse : 13.0 Remainder : 1.0 Log value of 10 : 2.302585092994046 java.math class and its methods | Set 3
🌐
Programiz
programiz.com › java-programming › library › math
Java Math Methods | Programiz
Java has a lot of Math methods that allow us to perform mathematical computations. In this reference page, you will find all the math methods available in Java. For example, if you need to get the square root of a number, use the sqrt() method.
🌐
Baeldung
baeldung.com › home › java › java numbers › a guide to the java math class
A Guide to the Java Math Class | Baeldung
January 8, 2024 - Similar to the above method, expm1() computes the Euler’s number raised to the power of the argument received, but it adds -1 (ex -1): ... When we have to work with geometric formulas, we always need trigonometric functions; the Math class provides these for us.
🌐
BeginnersBook -
beginnersbook.com › home › java › java math class
Java Math Class
October 20, 2022 - public class JavaExample { public static void main(String[] args) { double a = 5; double b = 3; System.out.println("Values of a and b are: "+a+", "+b); // Maximum of two numbers System.out.println("Maximum Number between a and b: " +Math.max(a, b)); // Minimum of two numbers System.out.println("Minimum Number between a and b: " +Math.min(a, b)); // a to the power b: 5^3 = 125 System.out.println("a to be power b: " + Math.pow(a, b)); } } ... public class JavaExample { public static void main(String[] args) { int a = 10; int b = 2; System.out.println("Values of a and b are: "+a+", "+b); System.out.println("a+b: " +Math.addExact(a, b)); System.out.println("a*b: " +Math.multiplyExact(a, b)); System.out.println("a-b: " +Math.subtractExact(a, b)); } }
🌐
Mickeyengel
cs.mickeyengel.com › lessons › java_04_mathAndString.php
Java Math/String Methods
For all examples, assume that String str="programming". ... returns the starting index of the first occurrence of a string in str. If the parameter string is not found, the method returns -1.There also exists a lastIndexOf method which does the same in reverse AND a version of indexOf that takes a second parameter where it starts the search
🌐
Stack Overflow
stackoverflow.com › questions › 39861034 › math-class-methods-and-random-numbers-java
Math Class, Methods, and random Numbers (Java) - Stack Overflow
Call your new randomStudy method from the main method. Highlight and copy the output shown in Eclipse. Paste the output at the bottom of your source code file. Add the text Results:above your output, and then comment out the text your just dded plus the output text. Your commented results should look something like this: /* Results: Math.pow(3.0, 2.0)= 9.0 Math.sqrt(25.0) = 5.0 Math.max(6, 2) = 6 Math.max(-50.0, 7.0) = 7.0 Math.random() = -random number- Min value: 1 Max value: 10 Average: 5.553 */
🌐
Java Almanac
javaalmanac.io › jdk › 1.2 › api › java › lang › Math.html
Java Platform 1.2 API Specification: Class Math
If two double values that are mathematical integers are equally close to the value of the argument, the result is the integer value that is even. ... Converts rectangular coordinates (b, a) to polar (r, theta). This method computes the phase theta by computing an arc tangent of a/b in the range ...