typestar

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

  1. max, abs, pow and sqrt cover the everyday operations.
  2. floor, ceil and round are three different opinions on halves.
  3. Integer.MAX_VALUE and Long.MIN_VALUE are 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.

Type this snippet

Step 3 of 3 in Variables & types, step 3 of 29 in Language basics.

← Previous Next →