Guest User

Untitled

a guest
Oct 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Lotto {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. Scanner sc = new Scanner(System.in);
  8.  
  9. System.out
  10. .println("Wieviele Felder des Lottoscheins wollen sie ausfüllen? ");
  11.  
  12. int amount = sc.nextInt();
  13.  
  14. // Speicherarray 2. Dimensional. 1 Dimension für die Felder, 2. für die
  15. // Zahlen
  16. int[][] speicher = new int[amount][6];
  17. // Prüfung ob eine passende Anzahl an Feldern eingegeben wurde
  18. if (amount > 12 || amount < 1) {
  19. System.out.println("Eingabe inkorrekt.");
  20. }
  21. // Befüllung des speicher Arrays
  22. for (int i = 0; i < amount; i++) {
  23.  
  24. for (int j = 0; j < 6; j++) {
  25.  
  26. int x = (int) (Math.random() * 49) + 1;
  27. speicher[i][j] = x;
  28. }
  29.  
  30. }
  31. // Ausgeben des Arrays
  32. for (int i = 0; i < speicher.length; i++) {
  33. System.out.println("Feld " + (i + 1) + ": ");
  34. for (int j = 0; j < 6; j++) {
  35. System.out.print(speicher[i][j] + " ");
  36. System.out.println();
  37. }
  38. }
  39. }
  40.  
  41. }
Add Comment
Please, Sign In to add comment