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.

Aufage zu Lösen (Suche Hilfe) !

Empfohlene Antworten

Veröffentlicht

Unzwar:

import java.util.Random;

class Lottozahlen{

public static void main(String arguments[]){

int[]LZ=new int[6];

int i,j=0;

Random r;

r = new Random();

LZ[0]=r.nextInt(50);

for (i=1;i<6;i++) { //füllt Array mit rnd Zahlen

LZ=r.nextInt(50);

for (j=0;j<i;j++){

if (LZ==LZ[j])

i--;

if (LZ==0)

i--;

else

;

}

}

for (i=0;i<6;i++){

System.out.println("Lottozahl "+(i+1)+ " lautet: " + LZ);

}

}

}

Dies ist (meine) Lottozahlziehmaschiene , nun möchte ich folgendes :

zu jeder zahl die gezogen wird soll ein anderer name hinzugefügt werden das heisst z.B. : 1 = Peter 2 = Hans usw.. so dass wenn ich meine ausgabe habe dort steht z.B: Lottozahl 1 = 43 : Susi

Lottozahl 2 = 24 : Rudolf

Lottozahl 3 = 12 : Sissy

Lottozahl 4 = 41 : Maddin

Lottozahl 5 = 33 : Markus

Lottozahl 6 = 22 : Eva

Kann mir wer weiterhelfen? :mod: :confused::confused::confused:

Mach dir nen String-Array mit 49 Namen drin und dann passt du dein Systout so an das der entsprechende Name ausgegeben wird:


String [] names = new String[49];

names[0] = "Johannes";

names[1] = "Paul";

names[2] = "Joseph";

names[3] = "Benedikt";

names[4] = "Jesus";

names[5] = "Maria";

...


System.out.println("Lottozahl "+(i+1)+ " lautet: " + LZ[i]); +" Name="+names[LZ[i]-1]

Bearbeitet von speedi

mach dir einfach ein statisches String-Array.

String [] namen = {"Peter", "Hans", ...} und sprich die einzelnen Namen über den index namen an.

import java.util.Random;

class Lottozahlen{

public static void main(String arguments[]){

int[]LZ=new int[6];

int i,j=0;

Random r;

r = new Random();

String [] names = new String[49];

names[0] = "Johannes";

names[1] = "Paul";

names[2] = "Joseph";

names[3] = "Benedikt";

names[4] = "Jesus";

names[5] = "†";

names[6] = "Bruce lee";

names[7] = "Jacki chan";

names[8] = "olum";

names[9] = "ananasikin";

names[10] = "Sikdelan";

names[11] = "Bush";

names[12] = "w.";

names[13] = "George";

names[14] = "Hussien";

names[15] = "Ossi";

names[16] = "Amokläufer";

names[17] = "kartoffelnködel";

names[18] = "Milka";

names[19] = "Ferrero";

names[20] = "123 Frites";

names[21] = "penny";

names[22] = "otto";

names[23] = "enneh";

names[24] = "marek";

names[25] = "keram";

names[26] = "ynnej";

names[27] = "radge";

names[28] = "Kinav";

names[29] = "Mehmet";

names[30] = "Ali";

names[31] = "Hassan";

names[32] = "Sukram THE MAGIC dlod";

names[33] = "Ash";

names[34] = "Exodia";

names[35] = "Yugi";

names[36] = "Arnold Schwarzenegger";

names[37] = "Michael Jordan";

names[38] = "Jean claude van damme";

names[39] = "Steven Segul";

names[40] = "Chucknorris";

names[41] = "Masterchief";

names[42] = "Postaldude";

names[43] = "hans-dieter-achim";

names[44] = "kenny";

names[45] = "neger";

names[46] = "ulli";

names[47] = "uwe";

names[48] = "Max Payne";

names[49] = "Ava devine";

LZ[0]=r.nextInt(50);

for (i=1;i<6;i++) { //füllt Array mit rnd Zahlen

LZ=r.nextInt(50);

for (j=0;j<i;j++){

if (LZ==LZ[j])

i--;

if (LZ==0)

i--;

else

;

}

}

for (i=0;i<6;i++){

System.out.println("Lottozahl "+(i+1)+ " lautet: " + LZ)+"Name="+names[LZ-1]

}

}

}

----------------------------------------------------------------------------------

Compiliere C:\Dokumente und Einstellungen\JAVA\Eigene Dateien\Lottozahlen.java mit Java-Compiler

Lottozahlen.java:75:68: not a statement

System.out.println("Lottozahl "+(i+1)+ " lautet: " + LZ)+"Name="+names[LZ-1]

^

Lottozahlen.java:75:83: ';' expected

System.out.println("Lottozahl "+(i+1)+ " lautet: " + LZ)+"Name="+names[LZ-1]

^

2 errors

Bitte keine Kommentare zu im Text enthaltenden wörter oda namen :D

Bearbeitet von seng fu

Dir ist eine Klammer verrutscht

for (i=0;i<6;i++){

System.out.println("Lottozahl "+(i+1)+ " lautet: " + LZ)+"Name="+names[LZ-1]

}

Muss sein

for (i=0;i<6;i++){

System.out.println("Lottozahl "+(i+1)+ " lautet: " + LZ+"Name="+names[LZ-1]);

}

und du wirst einen ArrayOutOfBoundsException bekommen, wenn du auf das Feld names[49] zugreifst

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.