w3resource

Java: Display and compute specified expressions

Java Basic: Exercise-9 with Solution

Expression Evaluation

Write a Java program to compute the specified expressions and print the output.

Specified Expression :
(25.5 * 3.5 - 3.5 * 3.5) / (40.5 - 4.5)

Pictorial Presentation:

Java: Display and compute specified expressions

Sample Solution:

Java Code:

public class Exercise9 {
 
    public static void main(String[] arg) {
        // Calculate and print the result of a mathematical expression
        System.out.println((25.5 * 3.5 - 3.5 * 3.5) / (40.5 - 4.5));
    }
} 

Explanation:

The above Java code calculates and prints the result of the following mathematical expression:

(25.5 * 3.5 - 3.5 * 3.5) / (40.5 - 4.5)

The code performs arithmetic operations, including multiplication, subtraction, and division, and displays the final result. In this case, the result will be printed to the console.

Sample Output:

2.138888888888889

Flowchart:

Flowchart: Display and compute specified expressions

Java Code Editor:

Previous: Write a Java program to display the specified pattern.
Next: Write a Java program to compute a specified formula.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/java-exercises/basic/java-basic-exercise-9.php