Java Exercises: Find the value of specified expression
Java Basic: Exercise-151 with Solution
Write a Java program to find the value of following 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:
public class Solution {
public static void main(String[] args) {
int r1 = (101 + 0) / 3;
double r2 = 3.0e-6 * 10000000.1;
boolean r3 = true && true;
boolean r4 = false && true;
boolean r5 = (false && false) || (true && true);
boolean r6 = (false || false) && (true && true);
System.out.println("(101 + 0) / 3)-> " + r1);
System.out.println("(3.0e-6 * 10000000.1)-> " + r2);
System.out.println("(true && true)-> " + r3);
System.out.println("(false && true)-> " + r4);
System.out.println("((false && false) || (true && true))-> " + r5);
System.out.println("(false || false) && (true && true)-> " + r6);
}
}
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:
Java Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Java program to test if a binary tree is a subtree of another binary tree.
Next: Write a Java program that accepts four integer from the user and prints equal if all four are equal, and not equal otherwise.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
Java: Tips of the Day
How to sort an ArrayList?
Collections.sort(testList); Collections.reverse(testList);
That will do what you want. Remember to import Collections though!
Ref: https://bit.ly/32urdSe
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework