public class Lotto2 {
public static void main(String[] args) {
if (args.length != 6) {System.out.println ("Sie dürfen nur 6 Argumente übergeben");return;}
int tipp[] = new int[6];
int n=0;
int treffer;
while (n<=5)
{
tipp[n] = Integer.parseInt(args[n]);
if (tipp[n]>49 | tipp[n]==0)
{
System.out.println("Der Wertebereich der Zahlen muss zwischen 1 und 49 liegen.");
return;
}
n++;
}
Ziehung x = new Ziehung();
while(x.pruefung() == false)
x = new Ziehung();
x.ausgabe();
treffer = x.treffer(tipp);
}
public static class Ziehung
{
int Zahlen[] = new int[6];
private Ziehung()
{
int n=0;
while (n<=5)
{
Zahlen[n]= (int)(Math.random()*49)+1;
n++;
}
}
private boolean pruefung()
{
int n=0;
while (n<=5)
{
int z=0;
while (z<=5)
{
if (n==z & n<5) z++;
if (n==z & n==5) return(true);
if (Zahlen[n]==Zahlen[z])
/*{System.out.println("Die "+Zahlen[n]+" kommt in ihrer Eingabe mehr als einmal vor");*/
return(false);
z++;
}
n++;
}
return (true);
}
private void ausgabe()
{
int n=0;
System.out.print("Ziehung: ");
while(n<=5)
{
System.out.print(" "+ Zahlen[n]);
n++;
}
System.out.println("");
}
private int treffer(int tipp[])
{
tipp = new int[6];
int n=0;
int x=0;
while (n<=5)
{
int z=0;
while (z<=5)
{
if (n==z & n<5) z++;
if (n==z & n==5) return(x);
if (Zahlen[n]==tipp[z])
{
x++;
z++;
}
}
n++;
}
}
}