Homework Exercises
Sections 1.2, 3.1-3.2
Due at start of next class (not the next lab), 1/31
- Rewrite each condition below in valid Java syntax (give a
boolean expression):
- x > y > z
- x and y are both less than 0
- neither x nor y is less than 0
- x is equal to y but not equal to z
- Suppose gpa is a variable containing the grade point
average of a student. Suppose the goal of the program is to let a
student know if he/she made the Dean's list (the gpa must
be 3.5 or above). Write an if... else... statement that
prints out the appropriate message (either "Congratulations -- you made the
Dean's List" or "Sorry you didn't make the Dean's List").
- Re-write each of the following statements using the operators
from pg. 19 of your text.
- numEmployees = numEmployees + 1;
- totalSalary = totalSalary + salary;
- totalWages = totalWages + hours*payRate;
- balance = balance - withdrawal;
- Determine the value of each variable after the execution of
the given segments of code (see pp. 30-32).
-
numA = 13;
numB = 5;
numC = ++numA + numB++;
-
numA = 10;
numB = 3;
numB += numA++;
System.out.println ("A: " + numA-- + " B: " + ++numB);
- The prefix and postfix increment and decrement operators can be handy, but,
as the book states, they should be used with care. Why is it generally not
a good idea to use them in expressions (as in the last problem)?