• Home
  • Jobs
  • Courses
  • Certifications
  • Companies
  • Online IDE
  • Login
  • Signup
MYTAT
  • Home
  • Jobs
  • Courses
  • Certifications
  • Companies
  • Online IDE
  • Login
  • Signup
Java
  • Java Introduction
  • Java Getting Started
  • Java Syntax
  • Java Comments
  • Java Variables
  • Java Data Types
  • Java Type Casting
  • Java Operators
  • Java Strings
  • Java Math
  • Java Booleans
  • Java If ... Else
  • Java Switch
  • Java While Loop
  • Java For Loop
  • Java Break And Continue
  • Java Arrays
  • Java Methods
  • Java Method Parameters
  • Java Method Overloading
  • Java Scope
  • Java Recursion
  • Java OOP
  • Java Classes And Objects
  • Java Class Attributes
  • Java Class Methods
  • Java Constructors
  • Java Modifiers
  • Java Encapsulation
  • Java Packages
  • Java Inheritance
  • Java Polymorphism
  • Java Inner Classes
  • Java Abstraction
  • Java Interface
  • Java Enums
  • Java User Input (Scanner)
  • Java Date And Time
  • Java ArrayList
  • Java LinkedList
  • Java HashMap
  • Java HashSet
  • Java Iterator
  • Java Wrapper Classes
  • Java Exceptions - Try...Catch
  • Java Regular Expressions
  • Java Threads
  • Java Lambda Expressions
  • Java Files
  • Java Create And Write To Files
  • Java Read Files
  • Java Delete Files
  • Home
  • Courses
  • Java
  • Java Math

Java Math

Previous Next

Java Math

The Java Math class has many methods that allows you to perform mathematical tasks on numbers.



Practice Excercise Practice now

Math.max(x,y)

The Math.max(x,y) method can be used to find the highest value of x and y:

Try it now

Example

Math.max(5, 10);



Practice Excercise Practice now

Math.min(x,y)

The Math.min(x,y) method can be used to find the lowest value of x and y:

Try it now

Example

Math.min(5, 10);



Practice Excercise Practice now

Math.sqrt(x)

The Math.sqrt(x) method returns the square root of x:

Try it now

Example

Math.sqrt(64);



Practice Excercise Practice now

Math.abs(x)

The Math.abs(x) method returns the absolute (positive) value of x:

Try it now

Example

Math.abs(-4.7);



Practice Excercise Practice now

Random Numbers

Math.random() returns a random number between 0.0 (inclusive), and 1.0 (exclusive):

Try it now

Example

Math.random();

To get more control over the random number, e.g. you only want a random number between 0 and 100, you can use the following formula:

Try it now

Example

int randomNum = (int)(Math.random() * 101);  // 0 to 100



Practice Excercise Practice now

Previous Next
COMPANY
  • About us
  • Careers
  • Contact Us
  • In Press
  • People
  • Companies List
Products
  • Features
  • Coding Assessments
  • Psychometric Assessment
  • Aptitude Assessments
  • Tech/Functional Assessments
  • Video Assessment
  • Fluency Assessment
  • Campus
 
  • Learning
  • Campus Recruitment
  • Lateral Recruitment
  • Enterprise
  • Education
  • K 12
  • Government
OTHERS
  • Blog
  • Terms of Services
  • Privacy Policy
  • Refund Policy
  • Mart Category
Partner
  • Partner Login
  • Partner Signup

Copyright © RVR Innovations LLP 2025 | All rights reserved - Mytat.co is the venture of RVR Innovations LLP