CSO Gaddis Java Chapter04 6ge
CSO Gaddis Java Chapter04 6ge
R4
Loops and
Files
• Example: IncrementDecrement.java
©2016 Pearson Education, Ltd. 4-4
Differences Between Prefix and Postfix
• When an increment or decrement are the only
operations in a statement, there is no difference
between prefix and postfix notation.
• When used in an expression:
– prefix notation indicates that the variable will be
incremented or decremented prior to the rest of the equation
being evaluated.
– postfix notation indicates that the variable will be
incremented or decremented after the rest of the equation
has been evaluated.
• Example: Prefix.java
true
boolean
statement(s)
expression?
false
while (condition)
{
statement;
statement;
statement;
}
• Example: SoccerTeams.java
statement(s)
true
boolean
expression?
false
boolean true
statement(s) update
expression?
false
Pass the name of the file that you Warning: if the file
wish to open as an argument to already exists, it will be
the PrintWriter constructor. erased and replaced
with a new file.
import java.io.*;
FileWriter fw =
new FileWriter("names.txt", true);
PrintWriter outFile =
new PrintWriter("A:\\PriceList.txt");