- Start with this code
class Coffee {
public static void main(String[] args) {
int cupsOfCoffee = 1;
while (cupsOfCoffee <= 100) {
System.out.println("Fry drinks cup of coffee #" + cupsOfCoffee);
cupsOfCoffee++;
}
}
}
-
We’ve provided a
while
loop that loops from1
to100
outputting a string on each iteration. Refactor (rewrite) this code as afor
loop.Remember, the syntax of a for loop looks like:
for (int i = 0; i < 5; i++) {
// code that will run
}
Example solution can be found in the Coffee.java file