Java: Find the value of specified expression
Evaluate Expressions
Write a Java program to find the value of a specified expression.
a) 101 + 0) / 3
b) 3.0e-6 * 10000000.1
c) true && true
d) false && true
e) (false && false) || (true && true)
f) (false || false) && (true && true)
Sample Solution:
Java Code:
Sample Output:
(101 + 0) / 3)-> 33 (3.0e-6 * 10000000.1)-> 30.0000003 (true && true)-> true (false && true)-> false ((false && false) || (true && true))-> true (false || false) && (true && true)-> false
Flowchart:
For more Practice: Solve these Related Problems:
- Write a Java program to evaluate a complex expression mixing arithmetic, bitwise, and logical operators without using extra parentheses.
- Write a Java program to compute the value of an expression that combines integer division, modulus, and floating-point multiplication in one statement.
- Write a Java program to evaluate a nested ternary expression that includes relational and bit-shift operations.
- Write a Java program to test Java operator precedence by evaluating an expression containing arithmetic, relational, and logical operators.
Go to:
PREV : Check Subtree in Binary Tree.
NEXT : Check Four Numbers Equal.
Java Code Editor:
Contribute your code and comments through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.