Example Application: calculator
x + yExample
System.out.println(String.format("%.2f + %.2f = %.2f", x, y, x + y));x - yExample
System.out.println(String.format("%.2f - %.2f = %.2f", x, y, x - y));x * yExample
System.out.println(String.format("%.2f * %.2f = %.2f", x, y, x * y));x / yExample
System.out.println(String.format("%.2f / %.2f = %.2f", x, y, x / y));Import:
import java.lang.Math;Code:
Math.PIExample
System.out.println("PI: " + Math.PI);Import:
import java.lang.Math;Code:
Math.pow(x, y)Example
System.out.println(String.format("%.2f ^ %.2f = %.2f", x, y, Math.pow(x, y)));Import:
import java.lang.Math;Generate random integers in a range.
new Random().nextInt(x) Example
Random integer in a range between min: 0 (inclusive) and max: X (inclusive).
System.out.println("Random Number: "+ new Random().nextInt(10));Import:
import java.lang.Math;Code:
Math.sqrt(x)Example
System.out.println(String.format("Square Root of %.2f = %.2f", x, Math.sqrt(x)));