Created
February 20, 2018 11:27
-
-
Save anonymous/2e5f59a6ec179f200dafc088c4cc5ab2 to your computer and use it in GitHub Desktop.
Quellcode für die Arrays und den Zufallgenerator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package itfe2_ae; | |
import java.util.*; | |
public class ITFE2_AE | |
{ | |
public static void aufgabe1() | |
{ | |
int[] x = new int[3]; | |
int wert = 44; | |
for (int i = 0 ; i < x.length ; i++) | |
{ | |
x[i]= wert; | |
wert+=11; | |
System.out.println(x[i]); | |
} | |
} | |
public static void aufgabe2() | |
{ | |
int[] x = new int[6]; | |
System.out.print("Zahlen eingeben: "); | |
for (int i = 0; i<x.length;i++) | |
x[i]=filter(); | |
System.out.print("Eingegebene Zahlen sind: "); | |
for (int i = 0; i<x.length;i++) | |
System.out.print(x[i]+" "); | |
} | |
public static int filter() | |
{ | |
Scanner reader = new Scanner(System.in); | |
if (reader.hasNextInt()) | |
return reader.nextInt(); | |
else | |
{ | |
System.out.print("Falsche Eingabe. Bitte nochmal versuchen:\t"); | |
return filter(); | |
} | |
} | |
public static void aufgabe3() | |
{ | |
int[] x = new int[6]; | |
for (int i = 0 ; i < x.length ; i++) | |
{ | |
x[i]= 5+i; | |
System.out.print(x[i]+" "); | |
} | |
} | |
public static void aufgabe4() | |
{ | |
Random rand = new Random(); | |
int[] lotto = new int[6]; | |
for (int i = 0 ; i < lotto.length ; i++) | |
{ | |
int zahl = Math.abs(rand.nextInt()%50); | |
boolean wiederholt = false; | |
for (int j = 0 ; j < i ; j++) | |
if (zahl == 0 || zahl == lotto[j]) | |
wiederholt = true; | |
if (!wiederholt) | |
{ | |
lotto[i] = zahl; | |
System.out.print(lotto[i]+ " "); | |
} | |
else | |
i--; | |
} | |
} | |
public static void main(String[] args) | |
{ | |
//aufgabe1(); | |
//aufgabe2(); | |
//aufgabe3(); | |
aufgabe4(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment