Math in Java
The static toolbox behind every calculation.
System.out.println(Math.max(3, 7));
System.out.println(Math.abs(-14));
System.out.println(Math.pow(2, 10));
System.out.println(Math.sqrt(144));
// rounding: floor, ceil and the nearest long
System.out.println(Math.floor(3.7) + " " + Math.ceil(3.2));
System.out.println(Math.round(2.5));
// the edges of the fixed-size integer types
System.out.println(Integer.MAX_VALUE);
System.out.println(Long.MIN_VALUE);
How it works
max,abs,powandsqrtcover the everyday operations.floor,ceilandroundare three different opinions on halves.Integer.MAX_VALUEandLong.MIN_VALUEare the type's hard edges.
The run, in numbers
- Lines
- 12
- Characters to type
- 408
- Tokens
- 123
- Three-star pace
- 105 tpm
At the three-star pace of 105 tokens a minute, this run takes about 70 seconds.
Step 3 of 3 in Variables & types, step 3 of 29 in Language basics.