Lecture 10: Java Operators Example
*, /, %, +, -, <, >=, !=, =
Java operators example
Assign '11 * 18' to a 'short' data type named 'answer1'
public class Lecture10 {
public static void main(String[] args) {
// TODO: Assign '11 * 18' to a 'short' data type named 'answer1'
}
}
Java operators example solution
short answer1 = 11 * 18;
Hi there, this is Marius from AlefTav Coding. In this lecture you will learn how to use operators in Java.
Operators are special symbols that you use in order to calculate a result. Some of these operators are: *, /, %, +, -, <, >=, !=, =
The example problem for this lecture states that you must assign '11 * 18' to a short data type named 'answer1'. In other words, you have to store the result of the multiplication, (x) expression, 11 * 18 at a storage location, named answer1.
In my solution, again, I use the Java pattern dataType storageName = value. The requirement says the data type must be short. Then, the storage name must be answer1. Finally, the initialization or assignment must be the expression 11 * 18. (11 multiplied by 18).
Let's examine the program. My class is Lecture10 with a method, main(). The solution code is short answer1 = 11 * 18;
In this lecture you learned how to use operators in Java.
To re-enforce what you have just learned, complete the following coding exercise:
Java operators coding exercise
public class Lecture11 {
public static void main(String[] args) {
// TODO: Assign ‘40 – 13' to a 'byte' data type named, ‘answer5’
}
}
My name is Marius from AlefTav Coding. Until next time, KEEP CODING.
Please be reminded to upvote, re-steem and share. For more of this you can find me at the following links.
https://busy.org/@mariusclaassen
https://steemit.com/@mariusclaassen
https://d.tube/#!/c/mariusclaassen
https://www.udemy.com/java-8-for-complete-beginners/learn/v4/overview