Compute expressions

The problem

Write a program that displays the result of:

(9.5 * 4.5 - 2.5 * 3) / (45.5 - 3.5)

Breaking it down

There is a lot of math utilities sprinkled throughout the java community but for this case we can use core math fundamentals. A numerator is a number that is represented above the line in a fraction. A denominator is the number below the line in a common fraction or commonly referred to as a divisor. Then dividing the two and outputting to the console will get us the results.

public static void main(String[] arg) {

    double numerator = 9.5 * 4.5 - 2.5 * 3;
    double denominator = 45.5 - 3.5;

    System.out.println(numerator / denominator);
}

Output

0.8392857142857143