treat arithmetic operations in the following order:
- Multiplication (*) and division
- Remainder (%)
- Addition (+) and
For example: 2*3+5=11
But if you want to calculate 3+5 first then multiply 2? What should
Using grouping operators
- parentheses ()
It is like 2*(3+5)=16.
But remember , inside parentheses () I
still follow the above order.
For example: 2*(3*2+4)=20,
Let us pretend you are a satellite dish installer, working for Directv or dish
network. You have 118 receivers in hands. There are 30 houses
applying to install dish in town. 20 house have 3 bedrooms. 10
houses have 4 bedroom. Each bedroom needs one receiver. You want
me to calculate how many receivers are left after you installed
all 30 houses.
OkieDokie Sir. As before, I will type code, compile and run.
public static void main(String args)
System.out.println("Number of left dish receivers="+NumberOfLeftReceiver);
Save it as dishInstaller.java. Compile: javac
dishInstaller.java. Then run it : java
dishInstaller. I get
: Number of left dish
Correct? OK. You are qualified for DirecTV or dish network now.
Go there and apply for a job.
Let's continue with that satellite dish installer project. This
time suppose you have 126 receivers. After you installed all those
houses? How many receivers left?
If DirecTV ask you to install more 4-bedroom houses by using the
left receivers, how many more houses you could install?
if dish network ask you to install 3-bedroom houses by using the
how many more houses you could install?
(Solution is here)