Hallo liebe Gemeinde,
ich habe ein Problem mit meinem Programm (Lottozahlen).
Hier ist mein Java-Code:
[highlight=Java]package lottozahlen;
/*
********************************************************************************
* Programmname: Lottozahlen *
* Datum: 7.04.2009 *
* Erstellt von: Jerome *
* *
* Beschreibung: *
* *
* Es sollen 6 Zahlen eingegeben werden und 6 automatisch erzeugt werden. *
* Dieses Programm vergleicht die 6 Zahlen und gibt die Übereinstimmungen aus. *
********************************************************************************
*/
import javax.swing.*;
public class Lottozahlen {
int eingabe (String dialogtext){
// Eingabe der 6 Tipps
final int NUM_ZAHL = 6;
final int ANZ_POTT = 49;
int[] Tipp = new int [NUM_ZAHL];
int[] Tipppott = new int [ANZ_POTT+1];
int H;
String sTipp = dialogtext;
for (int i = 0; i <= ANZ_POTT; i++)
Tipppott = 0;
for (int i = 0; i <= NUM_ZAHL; i++){
do{
Tipp = Integer.parseInt(JOptionPane.showInputDialog("Ihre " +(i+1)+ ". Tippzahl lautet: "));
} while (Tipp>49 || (Tipppott[Tipp]==1) || Tipp<1);
Tipppott[Tipp] = 1;
}
for (int i = 0; i <= 5; i++){
for (int j = 0; j <= 5; j++){
if(Tipp < Tipp[j]){
H = Tipp;
Tipp = Tipp[j];
Tipp[j] = H;
}
}
}
for (int i = 0; i <= 5; i++)
sTipp = sTipp + Tipp + ". ";
int eingabe = Integer.parseInt(sTipp);
return eingabe;
}
int lottozahlen (String dialogtext){
// Lottozahlen werden generiert
final int NUM_ZAHL = 6;
final int ANZ_POTT = 49;
int[] Lottozahlen = new int [NUM_ZAHL];
int[] Lottopott = new int [ANZ_POTT+1];
int H;
String sLotto = dialogtext;
for (int i = 0; i <= ANZ_POTT; i++)
Lottopott = 0;
for (int i = 0; i <= NUM_ZAHL; i++){
do {
Lottozahlen = (int)(Math.random()*ANZ_POTT)+1;
} while (Lottopott[Lottozahlen] == 1);
Lottopott[Lottozahlen] = 1;
}
for (int i = 0; i <= 5; i++){
for (int j = 0; j <= 5; j++){
if(Lottozahlen < Lottozahlen[j]){
H = Lottozahlen;
Lottozahlen = Lottozahlen[j];
Lottozahlen[j] = H;
}
}
}
for (int i = 0; i < NUM_ZAHL; i++)
sLotto = sLotto + Lottozahlen + ". ";
int lottozahlen = Integer.parseInt(sLotto);
return lottozahlen;
}
int treffer (int eingabe, int lottozahlen){
// Treffer werden gezaehlt
int trefferzaehler = 0;
for (int i = 0; i <= 5; i++){
for (int j = 0; j <= 5; j++){
if (eingabe == lottozahlen)
trefferzaehler++;
}
}
return trefferzaehler;
}
void ausgabe (int lottozahlen, int eingabe, int treffer){
// Ausgabe von lottozahlen, eingabe & treffer
String gZahlen = Integer.toString(lottozahlen);
String tipp = Integer.toString(eingabe);
String trefferzaehler = Integer.toString(treffer);
JOptionPane.showMessageDialog(null, gZahlen);
JOptionPane.showMessageDialog(null, tipp);
JOptionPane.showMessageDialog(null, trefferzaehler);
}
public static void main(String[] args) {
// Methodenaufruf von eingabe, lottozahlen & treffer
Lottozahlen meinLotto = new Lottozahlen();
int eingabe = meinLotto.eingabe("Ihre Zahlen lauten : ");
int lottozahlen = meinLotto.lottozahlen("Folgende Zahlen wurden gezogen : ");
int treffer = meinLotto.treffer(eingabe, lottozahlen);
meinLotto.ausgabe(lottozahlen, eingabe, treffer);
}
}[/highlight]
Und hier ist folgende Fehlermeldung:
[highlight=Java]Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6
at lottozahlen.Lottozahlen.eingabe(Lottozahlen.java:39)
at lottozahlen.Lottozahlen.main(Lottozahlen.java:153)[/highlight]
Ich hoffe ihr könnt mir weiterhelfen.
Bitte verbessert meine Fehler (oder eher was ich ändern soll) und gibt mir keine anderen Codes.
DANKE!
ich habe ein Problem mit meinem Programm (Lottozahlen).
Hier ist mein Java-Code:
[highlight=Java]package lottozahlen;
/*
********************************************************************************
* Programmname: Lottozahlen *
* Datum: 7.04.2009 *
* Erstellt von: Jerome *
* *
* Beschreibung: *
* *
* Es sollen 6 Zahlen eingegeben werden und 6 automatisch erzeugt werden. *
* Dieses Programm vergleicht die 6 Zahlen und gibt die Übereinstimmungen aus. *
********************************************************************************
*/
import javax.swing.*;
public class Lottozahlen {
int eingabe (String dialogtext){
// Eingabe der 6 Tipps
final int NUM_ZAHL = 6;
final int ANZ_POTT = 49;
int[] Tipp = new int [NUM_ZAHL];
int[] Tipppott = new int [ANZ_POTT+1];
int H;
String sTipp = dialogtext;
for (int i = 0; i <= ANZ_POTT; i++)
Tipppott = 0;
for (int i = 0; i <= NUM_ZAHL; i++){
do{
Tipp = Integer.parseInt(JOptionPane.showInputDialog("Ihre " +(i+1)+ ". Tippzahl lautet: "));
} while (Tipp>49 || (Tipppott[Tipp]==1) || Tipp<1);
Tipppott[Tipp] = 1;
}
for (int i = 0; i <= 5; i++){
for (int j = 0; j <= 5; j++){
if(Tipp < Tipp[j]){
H = Tipp;
Tipp = Tipp[j];
Tipp[j] = H;
}
}
}
for (int i = 0; i <= 5; i++)
sTipp = sTipp + Tipp + ". ";
int eingabe = Integer.parseInt(sTipp);
return eingabe;
}
int lottozahlen (String dialogtext){
// Lottozahlen werden generiert
final int NUM_ZAHL = 6;
final int ANZ_POTT = 49;
int[] Lottozahlen = new int [NUM_ZAHL];
int[] Lottopott = new int [ANZ_POTT+1];
int H;
String sLotto = dialogtext;
for (int i = 0; i <= ANZ_POTT; i++)
Lottopott = 0;
for (int i = 0; i <= NUM_ZAHL; i++){
do {
Lottozahlen = (int)(Math.random()*ANZ_POTT)+1;
} while (Lottopott[Lottozahlen] == 1);
Lottopott[Lottozahlen] = 1;
}
for (int i = 0; i <= 5; i++){
for (int j = 0; j <= 5; j++){
if(Lottozahlen < Lottozahlen[j]){
H = Lottozahlen;
Lottozahlen = Lottozahlen[j];
Lottozahlen[j] = H;
}
}
}
for (int i = 0; i < NUM_ZAHL; i++)
sLotto = sLotto + Lottozahlen + ". ";
int lottozahlen = Integer.parseInt(sLotto);
return lottozahlen;
}
int treffer (int eingabe, int lottozahlen){
// Treffer werden gezaehlt
int trefferzaehler = 0;
for (int i = 0; i <= 5; i++){
for (int j = 0; j <= 5; j++){
if (eingabe == lottozahlen)
trefferzaehler++;
}
}
return trefferzaehler;
}
void ausgabe (int lottozahlen, int eingabe, int treffer){
// Ausgabe von lottozahlen, eingabe & treffer
String gZahlen = Integer.toString(lottozahlen);
String tipp = Integer.toString(eingabe);
String trefferzaehler = Integer.toString(treffer);
JOptionPane.showMessageDialog(null, gZahlen);
JOptionPane.showMessageDialog(null, tipp);
JOptionPane.showMessageDialog(null, trefferzaehler);
}
public static void main(String[] args) {
// Methodenaufruf von eingabe, lottozahlen & treffer
Lottozahlen meinLotto = new Lottozahlen();
int eingabe = meinLotto.eingabe("Ihre Zahlen lauten : ");
int lottozahlen = meinLotto.lottozahlen("Folgende Zahlen wurden gezogen : ");
int treffer = meinLotto.treffer(eingabe, lottozahlen);
meinLotto.ausgabe(lottozahlen, eingabe, treffer);
}
}[/highlight]
Und hier ist folgende Fehlermeldung:
[highlight=Java]Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6
at lottozahlen.Lottozahlen.eingabe(Lottozahlen.java:39)
at lottozahlen.Lottozahlen.main(Lottozahlen.java:153)[/highlight]
Ich hoffe ihr könnt mir weiterhelfen.
Bitte verbessert meine Fehler (oder eher was ich ändern soll) und gibt mir keine anderen Codes.
DANKE!