Hirdetés

Keresés

Új hozzászólás Aktív témák

  • Szmeby
    tag

    Hello!

    Olvasom az Agyhullam: java címü könyvet. Ebben a kodban még mi a hiba:
    Probáltam megkereseni, de nem jöttem rá

    public class BeerSong { //14. oldal
    public static void main(String[] args) {
    int beerNum = 99;
    String word = "bottles";
    while (beerNum > 0)
    {
    if (beerNum == 1)
    {
    word = "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");
    }
    }
    }
    }

    A while cikluson kívül is van élet, ne félj oda is tenni valamit. Persze csak ha szükséges. ;)
    A két azonos szövegből pedig elég csak az egyiket megtartani.

    --- edit:
    A GameLauncher futtatható, mert van neki main metódusa.
    Bármely osztály, ami rendelkezik main metódussal, futtatható:

    public static void main(String[] args) {
    // ...
    }

  • WonderCSabo
    félisten

    Hello!

    Olvasom az Agyhullam: java címü könyvet. Ebben a kodban még mi a hiba:
    Probáltam megkereseni, de nem jöttem rá

    public class BeerSong { //14. oldal
    public static void main(String[] args) {
    int beerNum = 99;
    String word = "bottles";
    while (beerNum > 0)
    {
    if (beerNum == 1)
    {
    word = "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");
    }
    }
    }
    }

    Egy hiba mindenképpen van benne. Először kiírja 2x a cuccot, aztán csökkenti a számot és még egyszer kiírja. Ez a végén ahhoz fog vezetni, hogy "1 bottles of beer on the wall" is ki lesz írva.

  • emvy
    félisten

    Hello!

    Olvasom az Agyhullam: java címü könyvet. Ebben a kodban még mi a hiba:
    Probáltam megkereseni, de nem jöttem rá

    public class BeerSong { //14. oldal
    public static void main(String[] args) {
    int beerNum = 99;
    String word = "bottles";
    while (beerNum > 0)
    {
    if (beerNum == 1)
    {
    word = "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");
    }
    }
    }
    }

    Attol fugg, mit kellene csinalnia :D

Új hozzászólás Aktív témák