Java Exercises: Print the result of the specified operations
Java Basic: Exercise-4 with Solution
Write a Java program to print the result of the following operations.
Pictorial Presentation:
Sample Solution:
Java Code:
public class Exercise4 {
public static void main(String[] args) {
System.out.println(-5 + 8 * 6);
System.out.println((55+9) % 9);
System.out.println(20 + -3*5 / 8);
System.out.println(5 + 15 / 3 * 2 - 8 % 3);
}
}
Sample Output:
43 1 19 13
Flowchart:
Sample Solution:
Java Code:
public class Main {
public static void main(String[] args) {
int w = -5 + 8 * 6;
int x = (55 + 9) % 9;
int y = 20 + (-3 * 5 / 8);
int z = 5 + 15 / 3 * 2 - 8 % 3;
System.out.print(w + "\n" + x + "\n" + y + "\n" + z);
}
}
Flowchart:
Java Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Java program to divide two numbers and print on the screen.
Next: Write a Java program that takes two numbers as input and display the product of two numbers.
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