Java Reference
In-Depth Information
A for loop can be used to obtain the equivalent of the instruction “repeat the loop
body n times.”
Tracing variables is a good method for debugging loops.
An assertion check can be added to your Java code so that if the assertion is false,
your program halts with an error message.
Answers to Self-Test Exercises
1. if (score > 100)
System.out.println("High")
else
System.out.println("Low");
2. if (savings > expenses)
{
System.out.println("Solvent");
savings = savings - expenses;
expenses = 0;
}
else
{
System.out.println("Bankrupt");
}
3. if (number > 0)
System.out.println("Positive");
else
System.out.println("Not positive");
4. if (salary < deductions)
{
System.out.println("Crazy");
}
else
{
System.out.println("OK");
net = salary - deductions;
}
5. large
6. small
7. medium
Search WWH ::




Custom Search