[Solved] Calculate Expression - Java Task

  

2
Topic starter

Write a program that reads three floating point numbers from the console and calculates their result with the following formula:

expression formula

Then calculate the difference between the average of the three numbers and the average of the two formula.

Average (a, b, c) – Average (f1, f2);

The results must look like this:

results table

1 Answer
2

Interesting task! Here is my solution to it:

import java.util.Scanner;
 
public class CalculateExpression {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
 
        double a = scanner.nextDouble();
        double b = scanner.nextDouble();
        double c = scanner.nextDouble();
 
        double firstResult = Math.pow(((a * a + b * b) / (a * a - b * b)), (a + b + c) / Math.sqrt(c));
        double secondResult = Math.pow((a * a + b * b - c * c * c), a - b);
        double average = ((firstResult + secondResult) / 2) - ((a + b + c) / 3);
        System.out.println(average);
    }
}
Share: