PHP interesse |
|
Kan iemand mij vertellen waarom de aanpassingen doen wat ze doen?
Hieronder volgt de eerste code. Hierbij staat bij het runnen als eerste regel "1 bottels of beer . . . . . ", dus een s er achter.
Bij de code die daaronder volgt niet meer, ik snap alleen niet hoe dat komt en dan bedoel ik vooral de wijziging op regel 16 (ook onderaan is iets gewijzigd, die kan ik overigens nog begrijpen)
public class BeerSong {
public static void main (String[] args) {
int beerNum = 99;
String word = "bottles";
while (beerNum > 0) {
if (beerNum == 1) {
word = "bottle"; // singular, as in ONE bottle.
}
System.out.println(beerNum + " " + word + " of beer on the wall");
System.out.println(beerNum + " " + word + " of beer.");
System.out.println("Take one down.");
System.out.println("Pass it around.");
beerNum = beerNum - 1;
if (beerNum > 0) {
System.out.println(beerNum + " " + word + " of beer on the wall");
} else {
System.out.println("No more bottles of beer on the wall");
} // end of else
} // end of while loop
} // end of main method
} // end of class
public class BeerSong { public static void main (String[] args ) { int beerNum = 99; while (beerNum > 0) { if (beerNum == 1) { word = "bottle"; // singular, as in ONE bottle. } System. out. println(beerNum + " " + word + " of beer on the wall"); System. out. println(beerNum + " " + word + " of beer."); System. out. println("Take one down."); System. out. println("Pass it around."); beerNum = beerNum - 1; if (beerNum > 0) { System. out. println(beerNum + " " + word + " of beer on the wall"); } else { System. out. println("No more bottles of beer on the wall"); } // end of else } // end of while loop } // end of main method } // end of class
public class BeerSong {
public static void main (String[] args) {
int beerNum = 99;
String word = "bottles";
while (beerNum > 0) {
if (beerNum == 1) {
word = "bottle"; // singular, as in ONE bottle.
}
System.out.println(beerNum + " " + word + " of beer on the wall");
System.out.println(beerNum + " " + word + " of beer.");
word = "bottles";
System.out.println("Take one down.");
System.out.println("Pass it around.");
beerNum = beerNum - 1;
if (beerNum == 0) {
System.out.println("No more bottles of beer on the wall");
} // end of if
} // end of while loop
} // end of main method
} // end of class
public class BeerSong { public static void main (String[] args ) { int beerNum = 99; while (beerNum > 0) { if (beerNum == 1) { word = "bottle"; // singular, as in ONE bottle. } System. out. println(beerNum + " " + word + " of beer on the wall"); System. out. println(beerNum + " " + word + " of beer."); word = "bottles"; System. out. println("Take one down."); System. out. println("Pass it around."); beerNum = beerNum - 1; if (beerNum == 0) { System. out. println("No more bottles of beer on the wall"); } // end of if } // end of while loop } // end of main method } // end of class
|