-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaths.java
More file actions
39 lines (37 loc) · 1.17 KB
/
Maths.java
File metadata and controls
39 lines (37 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.util.Random;
public class Maths {
public static void main(String[] args) {
/*
* Math.max()
* Argument: x,y
* This method will help us to get max number between a and b
*/
System.out.println(Math.max(20, 40)); // 40
/*
* Math.min()
* Argument: x,y -> int
* This method will help us to get min number between a and b
*/
System.out.println(Math.min(20, 40)); // 20
/*
* Math.sqrt()
* Argument: x -> int
* This method will help us to sqrt any number
*/
System.out.println((int) Math.sqrt(64)); // 8
/*
* Math.abs()
* Argument: x -> int
* This method will help us to get absolute positive value
*/
System.out.println(Math.abs(-64.69)); // 64.69
/*
* Math.random()
* Argument: not required
* This method will help us to generate random number
*/
System.out.println((int) Math.random() * 20); // (Random)
// or
System.out.println(new Random().nextInt(10) + 1); // generate random number including 1 to 10
}
}