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.

Zufallszahlen in Java

Empfohlene Antworten

Veröffentlicht

Hallo erstmal!!

Also ich werde demnächst eine Gfs halten müssen. Und zwar soll ein Programm geschrieben werden das wie ein Lotto Spiel funktioniert. Also "6 aus 49" und mein Problem ist, ich hab absolut keine Ahnung wie Java 6 Zufallszahlen generieren sollte...hab schon gelesen das man da ne neue Klasse erstellen soll aber ich bekomm des definitiv nicht hin. Hat einer von euch sowas schonmal gemacht?

Ich hoff ihr könnt mir helfen :)

Danke im Vorraus!!

PS: Programmiert wird mit dem JCreator! (Java)

Random randomizer = new Random();

r1 = randomizer.nextInt();

Random randomizer = new Random();

int r1 = randomizer.nextInt(49);

while(r1 == 0){

r1 = randomizer.nextInt(49);

}


12345

//09.01.2007

import java.io.*;

public class TottoLotto

{

public static void main (String argv []) throws IOException

{

//Dimensionierung

int zaehler1, zaehler2, tippanzahl;

int lottotipp [] [];

String str;

BufferedReader eingabe = new BufferedReader(new InputStreamReader (System.in));

//Anlegen des mehrdimensionalen Arrays mit bestimmter Größe

System.out.print("Herzlich Willkommen beim Online-Lotto!");

System.out.print("");

System.out.println("Bitte geben Sie die Anzahl der Spieler an die einen Tipp abgeben moechten:");

str = eingabe.readLine ();

tippanzahl = Integer.parseInt (str);

lottotipp = new int [tippanzahl] [6];

for (zaehler1 = 1; zaehler1 <= tippanzahl; zaehler1++)

{

System.out.print("Eingabe des "+zaehler1+" .ten Tipps!:");

for (zaehler2 = 1; zaehler2 <= 6; zaehler2++)

{

System.out.print("Bitte geben Sie die " +(zaehler2)+ ".te Lottozahl ein!");

str = eingabe.readLine();

lottotipp [zaehler1-1] [zaehler2-1] = Integer.parseInt (str);

System.out.println();

}

}

Random randomizer = new Random();

int r1 = randomizer.nextInt(49);

while(r1 == 0){

r1 = randomizer.nextInt(49);

}

}

}

Also soweit bin ich gekommen...eure Antwort hab ich erstmal nur eingefügt, weil ich gleich mal den Fehler "cannot find symbol class Random"!! Ja und des sagt mir net grad viel!! :rolleyes:

Wie mach ich das nun genau das er mir das ausgibt also diese 6 Zufallszahlen?

Dann füg' bitte ganz oben mal

import java.util.Random;

ein.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

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.