Skip to content

Instantly share code, notes, and snippets.

@ionelh
Created February 1, 2020 17:17
Show Gist options
  • Save ionelh/b969590239b6649c07dc1604d4da4d21 to your computer and use it in GitHub Desktop.
Save ionelh/b969590239b6649c07dc1604d4da4d21 to your computer and use it in GitHub Desktop.
// integers default to integers
System.out.println(42 + 2);
System.out.println(42 - 2);
System.out.println(42 * 2);
System.out.println(42 / 4);
System.out.println(42 % 4);
// doubles default to doubles
System.out.println(42.0 / 4.0);
// Numerous math functions (check the doc for complete list)
System.out.println(Math.abs(-1));
System.out.println(Math.ceil(4.25));
System.out.println(Math.floor(4.25));
System.out.println(Math.round(4.25));
System.out.println(Math.max(4,5));
System.out.println(Math.min(4,5));
System.out.println(Math.log(1));
System.out.println(Math.log10(1));
System.out.println(Math.pow(2,2));
System.out.println(Math.sqrt(4));
System.out.println(Math.random());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment