PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Java Lotto Programm



Perishand
28.05.2009, 23:27
Ich habe mal ein kleines "Lotto" Programm geschrieben, es ist nichts weltbewegendes das weiß ich, bin in der absoluten Anfangsphase in Sachen Java.

Es ist vielleicht für den ein oder anderen eine kleine Hilfe. Ich hoffe es gefällt euch, wenns auch nichts großes ist.


//28.05.2009
//Details: Lotto Programm

import java.io.*;
import java.util.*;


public class Lotto {

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

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

int i,j,zaehler;
int[] zahlen = new int[50];
int[] tipp = new int[7];
String eingabe;

System.out.println("Lotto Programm");
System.out.println("Moechten Sie dieses Programm ausfuehren?");
System.out.println(" <j>a");
System.out.println(" <n>ein");
System.out.print("Ihre Eingabe: ");

eingabe = in.readLine();

if (eingabe.equals("j")||eingabe.equals("J")) {

System.out.println("-------------------------------------------------------");

System.out.println("Bitte geben Sie jetzt ihre 6 Zahlen ein:");
System.out.println();

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

System.out.print("Zahl " + i + ": ");
tipp[i] = Integer.parseInt(in.readLine());

if (tipp[i] > 49) {

System.out.println("Falsche Eingabe, Programm wird unterbrochen!");
System.exit(0);

}//if (tipp[i] > 49)

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

if (tipp[i] == tipp[j]) {

System.out.println("Bitte keine Zahl doppelt angeben!");
System.exit(0);

}//if (tipp[i] == tipp[j])
}//for (j=0;j<=6;j++)
}//for (i=1;i<=6;i++)


System.out.println("-------------------------------------------------------");

lottozahlen(tipp);


}//if (eingabe.equals("j")||eingabe.equals("J"))

else {

System.out.println("Programm wird beendet");

}//else


}//public static void (String argv[]) throws IOException

public static void lottozahlen(int[] tipp) {

Random generator = new Random();

int i,j,zaehler,richtig=0;
int[] zahlen = new int[50];
int[] zufaellig = new int[6];
boolean tipprichtig = false;

for (i=1;i<=49;i++) {

zahlen[i] = i;

}//for (i=0;i<49;i++)


for (i=1;i<=49;i++) {

zaehler = zahlen[i] % 7;

for (j=1;j<7;j++) {

if (zahlen[i] == tipp[j]) {

System.out.print(" *");
tipprichtig = true;


}//if (zahlen[i] == tipp[j])

}//for (j=1;j<7;j++)

if (tipprichtig == false){

if (zahlen[i] < 10) {

System.out.print(" " + zahlen[i]);

}//if (zahlen[i] < 10)

else {

System.out.print(" " + zahlen[i]);

}//else

}//if (tipprichtig == false)

tipprichtig = false;

if (zaehler == 0) {

System.out.println();

}//if (zaehler = 0)

}//for (i=0;i<7;i++)

System.out.println("-------------------------------------------------------");
System.out.println("Jetzt werden die zufaelligen Zahlen erstellt:");
System.out.println();

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

zufaellig[i] = generator.nextInt(49);

if (i == 5) {

System.out.print(zufaellig[i]);

}//if (i == 5)
else {

System.out.print(zufaellig[i] + " | ");

}//else

}//for (i=0;i<6;i++)

System.out.println();
System.out.println("-------------------------------------------------------");


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

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

if (tipp[i] == zufaellig[j]) {

System.out.println("Die Zahl " + zufaellig[j] + " war richtig");
richtig++;

}//if (zahlen[i] == zufaellig[j])
}//for (i=1;i<=49;i++)
}//for (j=0;j<6;j++)

if (richtig == 0) {

System.out.println("Leider kein Treffer, versuche es erneut");

}//if (richtig == 0)
System.out.println("-------------------------------------------------------");

}//public static void lottozahlen(int[] tipp)
}//public class Lotto



Hier als NoPaste (besser zu erkennen und besser formatiert)

http://nopaste.free-hack.com/index.php?id=669a47cf0a