![Page 1: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/1.jpg)
int x = 3;
if (x > 1)
if (x > 2) {
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
![Page 2: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/2.jpg)
int x = 3;
if (x > 1)
if (x > 2) {
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
x = 3
![Page 3: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/3.jpg)
int x = 3;
if (x > 1)
if (x > 2) {
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
x > 1
x = 3
true
![Page 4: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/4.jpg)
int x = 3;
if (x > 1)
if (x > 2) {
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
x > 1
x = 3
x > 2
true
true
![Page 5: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/5.jpg)
int x = 3;
if (x > 1)
if (x > 2) {
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
x > 1
x = 3
x > 2
{ true
true
![Page 6: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/6.jpg)
int x = 3;
if (x > 1)
if (x > 2) {
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
x > 1
x = 3
x > 3
x > 2
{ true
true
true
![Page 7: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/7.jpg)
int x = 3;
if (x > 1)
if (x > 2) {
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
x > 1
x = 3
x > 3
x > 2
“one”
{ true
true
true
![Page 8: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/8.jpg)
int x = 3;
if (x > 1)
if (x > 2) {
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
x > 1
x = 3
x > 3
x > 2
“one”
{
}
true
true
true
![Page 9: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/9.jpg)
int x = 3;
if (x > 1)
if (x > 2) {
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
x > 1
x = 3
x > 3
x > 2
“one”
{
}
true
true
true
![Page 10: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/10.jpg)
int x = 3;
if (x > 1)
if (x > 2) {
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
x > 1
x = 3
x > 3
x > 2
“one”
{
}
true
true
true
![Page 11: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/11.jpg)
int x = 3;
if (x > 1)
if (x > 2) {
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
x > 1
x = 3
x > 3
x > 2
“one”
{
}
true
true
true
![Page 12: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/12.jpg)
int x = 3;
if (x > 1)
if (x > 2) {
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
x > 1
x = 3
x > 3
x > 2
“three” “one”
{
}
true
true
true
![Page 13: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/13.jpg)
int x = 3;
if (x > 1)
if (x > 2) {
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
x > 1
x = 3
x > 3
x > 2
“three” “one”
{
}
true
true
true
![Page 14: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/14.jpg)
int x = 3;
if (x > 1)
if (x > 2) {
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
x > 1
x = 3
x > 3
x > 2
“three” “one”
{
}
true
true
true
![Page 15: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/15.jpg)
int x = 3;
if (x > 1)
if (x > 2) {
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
x > 1
x = 3
x > 3
x > 2
“three” “one”
{
}
true
true
true
![Page 16: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/16.jpg)
int x = 3;
if (x > 1)
if (x > 2) {
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
x > 1
x = 3
x > 3
x > 2
“three” “one”
“four”
{
}
true
true
true
![Page 17: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/17.jpg)
int x = 3;
if (x > 1)
if (x > 2) {
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
x > 1
x = 3
x > 3
x > 2
“three” “one”
“four”
{
}
true
true
true
![Page 18: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/18.jpg)
int x = 3;
if (x > 1)
if (x > 2) {
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
x > 1
x = 3
x > 3
x > 2
“three” “one”
“four”
{
}The end.
true
true
true
![Page 19: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/19.jpg)
int x = 3;
if (x > 1)
if (x > 2) {
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
x > 1
x = 3
x > 3
x > 2
“three” “one”
“four”
{
}The end. The end. Nothing gets printed.
true
true
true
![Page 20: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/20.jpg)
int x = 3;
if (x > 1)
if (x > 2) {
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
Old problem
![Page 21: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/21.jpg)
int x = 3;
if (x > 1) {
if (x > 2)
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
New problem
![Page 22: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/22.jpg)
int x = 3;
if (x > 1)
if (x > 2) {
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
Old problem
![Page 23: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/23.jpg)
int x = 3;
if (x > 1) {
if (x > 2)
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
New problem
![Page 24: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/24.jpg)
int x = 3;
if (x > 1) {
if (x > 2)
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
New problem
else w/out if
Does not compile!
![Page 25: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/25.jpg)
int x = 3;
if (x > 1) {
if (x > 2)
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
New problem
else w/out if
Does not compile!
The only solution, then, is to carefully draw the flowchart!
![Page 26: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/26.jpg)
int x = 3;
if (x > 1) {
if (x > 2)
if (x > 3)
System.out.println("one");
} else System.out.println("three");
else System.out.println("four");
New problem
else w/out if
Does not compile!
The only solution, then, is to carefully draw the flowchart!
There really isn’t any reliable, uniform shortcut alternative to that.
![Page 27: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/27.jpg)
Let’s take a look at the lab assignment.
![Page 28: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/28.jpg)
initialize the amount the user needs to pay
while (the amount due is more than zero) {
prompt the user for input (a line)
get the line and prepare to take it apart
while (there are still tokens available) {
get next token (call it token)
interpret it, and update amount
}
// if you get here you’re done with the line
// but the amount due can still be positive
}
// if you get here the amount due is zero or less
![Page 29: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/29.jpg)
initialize the amount the user needs to pay
while (the amount due is more than zero) {
prompt the user for input (a line)
get the line and prepare to take it apart
while (there are still tokens available) {
get next token (call it token)
interpret it, and update amount
}
// if you get here you’re done with the line
// but the amount due can still be positive
}
// if you get here the amount due is zero or less
![Page 30: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/30.jpg)
initialize the amount the user needs to pay
while (the amount due is more than zero) {
prompt the user for input (a line)
get the line and prepare to take it apart
while (there are still tokens available) {
get next token (call it token)
interpret it, and update amount
}
// if you get here you’re done with the line
// but the amount due can still be positive
}
// if you get here the amount due is zero or less
![Page 31: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/31.jpg)
initialize the amount the user needs to pay
while (the amount due is more than zero) {
prompt the user for input (a line)
get the line and prepare to take it apart
while (there are still tokens available) {
get next token (call it token)
interpret it, and update amount
}
// if you get here you’re done with the line
// but the amount due can still be positive
}
// if you get here the amount due is zero or less
![Page 32: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/32.jpg)
initialize the amount the user needs to pay
while (the amount due is more than zero) {
prompt the user for input (a line)
get the line and prepare to take it apart
while (there are still tokens available) {
get next token (call it token)
interpret it, and update amount
}
// if you get here you’re done with the line
// but the amount due can still be positive
}
// if you get here the amount due is zero or less
![Page 33: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/33.jpg)
initialize the amount the user needs to pay
while (the amount due is more than zero) {
prompt the user for input (a line)
get the line and prepare to take it apart
while (there are still tokens available) {
get next token (call it token)
interpret it, and update amount
}
// if you get here you’re done with the line
// but the amount due can still be positive
}
// if you get here the amount due is zero or less
![Page 34: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/34.jpg)
initialize the amount the user needs to pay
while (the amount due is more than zero) {
prompt the user for input (a line)
get the line and prepare to take it apart
while (there are still tokens available) {
get next token (call it token)
interpret it, and update amount
}
// if you get here you’re done with the line
// but the amount due can still be positive
}
// if you get here the amount due is zero or less
![Page 35: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/35.jpg)
initialize the amount the user needs to pay
while (the amount due is more than zero) {
prompt the user for input (a line)
get the line and prepare to take it apart
while (there are still tokens available) {
get next token (call it token)
interpret it, and update amount
}
// if you get here you’re done with the line
// but the amount due can still be positive
}
// if you get here the amount due is zero or less
![Page 36: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/36.jpg)
initialize the amount the user needs to pay
while (the amount due is more than zero) {
prompt the user for input (a line)
get the line and prepare to take it apart
while (there are still tokens available) {
get next token (call it token)
interpret it, and update amount
}
// if you get here you’re done with the line
// but the amount due can still be positive
}
// if you get here the amount due is zero or less
![Page 37: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/37.jpg)
initialize the amount the user needs to pay
while (the amount due is more than zero) {
prompt the user for input (a line)
get the line and prepare to take it apart
while (there are still tokens available) {
get next token (call it token)
interpret it, and update amount
}
// if you get here you’re done with the line
// but the amount due can still be positive
}
// if you get here the amount due is zero or less
![Page 38: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/38.jpg)
initialize the amount the user needs to pay
while (the amount due is more than zero) {
prompt the user for input (a line)
get the line and prepare to take it apart
while (there are still tokens available) {
get next token (call it token)
interpret it, and update amount
}
// if you get here you’re done with the line
// but the amount due can still be positive
}
// if you get here the amount due is zero or less
![Page 39: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/39.jpg)
initialize the amount the user needs to pay
while (the amount due is more than zero) {
prompt the user for input (a line)
get the line and prepare to take it apart
while (there are still tokens available) {
get next token (call it token)
interpret it, and update amount
}
// if you get here you’re done with the line
// but the amount due can still be positive
}
// if you get here the amount due is zero or less
![Page 40: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/40.jpg)
initialize the amount the user needs to pay
while (the amount due is more than zero) {
prompt the user for input (a line)
get the line and prepare to take it apart
while (there are still tokens available) {
get next token (call it token)
interpret it, and update amount
}
// if you get here you’re done with the line
// but the amount due can still be positive
}
// if you get here the amount due is zero or less
![Page 41: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/41.jpg)
initialize the amount the user needs to pay
while (the amount due is more than zero) {
prompt the user for input (a line)
get the line and prepare to take it apart
while (there are still tokens available) {
get next token (call it token)
interpret it, and update amount
}
// if you get here you’re done with the line
// but the amount due can still be positive
}
// if you get here the amount due is zero or less
![Page 42: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/42.jpg)
initialize the amount the user needs to pay
while (the amount due is more than zero) {
prompt the user for input (a line)
get the line and prepare to take it apart
while (there are still tokens available) {
get next token (call it token)
interpret it, and update amount
}
// if you get here you’re done with the line
// but the amount due can still be positive
}
// if you get here the amount due is zero or less
![Page 43: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/43.jpg)
initialize the amount the user needs to pay
while (the amount due is more than zero) {
prompt the user for input (a line)
get the line and prepare to take it apart
while (there are still tokens available) {
get next token (call it token)
interpret it, and update amount
}
// if you get here you’re done with the line
// but the amount due can still be positive
}
// if you get here the amount due is zero or less
![Page 44: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/44.jpg)
initialize the amount the user needs to pay
while (the amount due is more than zero) {
prompt the user for input (a line)
get the line and prepare to take it apart
while (there are still tokens available) {
get next token (call it token)
interpret it, and update amount
}
// if you get here you’re done with the line
// but the amount due can still be positive
}
// if you get here the amount due is zero or less
![Page 45: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/45.jpg)
initialize the amount the user needs to pay
while (the amount due is more than zero) {
prompt the user for input (a line)
get the line and prepare to take it apart
while (there are still tokens available) {
get next token (call it token)
interpret it, and update amount
}
// if you get here you’re done with the line
// but the amount due can still be positive
}
// if you get here the amount due is zero or less
![Page 46: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/46.jpg)
initialize the amount the user needs to pay
while (the amount due is more than zero) {
prompt the user for input (a line)
get the line and prepare to take it apart
while (there are still tokens available) {
get next token (call it token)
interpret it, and update amount
}
// if you get here you’re done with the line
// but the amount due can still be positive
}
// if you get here the amount due is zero or less
![Page 47: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/47.jpg)
initialize the amount the user needs to pay
while (the amount due is more than zero) {
prompt the user for input (a line)
get the line and prepare to take it apart
while (there are still tokens available) {
get next token (call it token)
interpret it, and update amount
}
// if you get here you’re done with the line
// but the amount due can still be positive
}
// if you get here the amount due is zero or less
![Page 48: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/48.jpg)
initialize the amount the user needs to pay
while (the amount due is more than zero) {
prompt the user for input (a line)
get the line and prepare to take it apart
while (there are still tokens available) {
get next token (call it token)
interpret it, and update amount
}
// if you get here you’re done with the line
// but the amount due can still be positive
}
// if you get here the amount due is zero or less
![Page 49: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/49.jpg)
initialize the amount the user needs to pay
while (the amount due is more than zero) {
prompt the user for input (a line)
get the line and prepare to take it apart
while (there are still tokens available) {
get next token (call it token)
interpret it, and update amount
}
// if you get here you’re done with the line
// but the amount due can still be positive
}
// if you get here the amount due is zero or less
![Page 50: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/50.jpg)
initialize the amount the user needs to pay
while (the amount due is more than zero) {
prompt the user for input (a line)
get the line and prepare to take it apart
while (there are still tokens available) {
get next token (call it token)
interpret it, and update amount
}
// if you get here you’re done with the line
// but the amount due can still be positive
}
// if you get here the amount due is zero or less
![Page 51: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/51.jpg)
initialize the amount the user needs to pay
while (the amount due is more than zero) {
prompt the user for input (a line)
get the line and prepare to take it apart
while (there are still tokens available) {
get next token (call it token)
interpret it, and update amount
}
// if you get here you’re done with the line
// but the amount due can still be positive
}
// if you get here the amount due is zero or less
![Page 52: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/52.jpg)
So you can give the user the change (if any).
initialize the amount the user needs to pay
while (the amount due is more than zero) {
prompt the user for input (a line)
get the line and prepare to take it apart
while (there are still tokens available) {
get next token (call it token)
interpret it, and update amount
}
// if you get here you’re done with the line
// but the amount due can still be positive
}
// if you get here the amount due is zero or less
![Page 53: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/53.jpg)
Now let’s talk about the homework problems…
![Page 54: int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one");](https://reader036.vdocuments.us/reader036/viewer/2022062409/56814e4a550346895dbbd19c/html5/thumbnails/54.jpg)
1. The Wizard Problem
You are to define a class of objects that (once created) can take simple
(math) questions. The following three requirements are to be met:
a) wizards know how to calculate the greatest common divisor of two integers
b) a wizard can list the prime factors of any positive integer
c) a wizard can tell you if an integer is prime or not