settingsAccountsettings
Menusettings

Q: Calculate Expression - Java Task

+6 votes

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

asked in Java category by user eiorgert
edited by user golearnweb

1 Answer

+1 vote
 
Best answer

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);
    }
}
answered by user hues
edited by user golearnweb
...