Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hallo erstmal, ich soll für die Schule ein Glücksspiel erstellen und habe folgendes Problem. Ich würde gerne einen String ausgeben wenn das Guthaben des Spielers auf 0 gesunken ist, aber leider klappt das nicht ganz wie ich mir das Vorstelle bzw. gar nicht.

Hier mal ein Ausschnitt vom Code:

    if(!sZaehler.equals("0"))

        {

            String sKnopf = request.getParameter("knopf");

            if (sKnopf == null) {

                sKnopf = "erster Seitenaufruf";

            }

            if (sKnopf.equals("Einfach")) {

                iZaehler = iZaehler + 500;

            }

            if (sKnopf.equals("Doppelt")) {

            iZaehler = iZaehler + 1000;

            }

            if (sKnopf.equals("Dreifach")) {

                iZaehler = iZaehler - 1500;

            }

            else

            {

                String ergebnis = "Verloren!";

            }

        }

    %>

    <body><br>

        <form action="index.jsp" method="post">

            <input type="text" readonly="true" name="zaehler" value="<%=iZaehler%>"/><br>

            <input type="submit" name="knopf" value="Einfach" />

            <input type="submit" name="knopf" value="Doppelt" />

            <input type="submit" name="knopf" value="Dreifach" />

        </form>

            <%=ergebnis%>

    </body>

Danke schonmal im vorraus, ich hoffe ihr könnt mir weiterhelfen.

Gruß Aero-Biba

Dein else hängt am falschen Block.


 if(!"0".equals(sZaehler)) {

            // ...

            if (sKnopf.equals("Dreifach")) {

                iZaehler = iZaehler - 1500;

            }

            // hier kein else

   }   else { // sondern hier

                String ergebnis = "Verloren!";

            }


Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.