OK. You have
learned a lot in previous lessons. By using what you learned so far,
you could ask me to do a lot of things
Let us play a little bit. Let us pretend that you are a doctor.
Your dog catch a cold. He got fever, red eye, running nose and sneezing
a lot! You gave a prescription and ask me to calculate how much money
the medcines will cost.
The prescription is:
I called pharmacy and find out that yellow pill
cost 0.83 per pill and blue pill
is 1.95 per pill. So
I type the following code to calculate the cost:
5 yellow pills
4 blue pills
for allergy symptoms (sneezing, running nose)
public static void main(String args)
System.out.println("Total medicine cost="+totalCost);
Save it as medicine.java. Then I compile the code: javac
Then I run the code: java
Now i get the result: Total
In the above code, you may see that a statement may write into serveral
lines(highlighted in red).
OK, doctor, I finish my job.
Suppose you will have a birthday party next Saturday. You got $234
dollars from your grandparentsa. You plan to invite friends to
War (3)".. Every one needs a ticket ($5), a drink ($1.1) and
popcorn($2.3). How many friends you could invite at most (Don't
Please print out something like "Maximum number of friends="...
(Solution is here).