Advertisement
Guest User

Untitled

a guest
Sep 14th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1.  
  2. public class aufgabe2 {
  3. static int n = IO.readInt("Bitte n Kinder eingeben: ");
  4. static int m = IO.readInt("Bitte m Runden eingeben: ");
  5.  
  6. public static void main(String[] args) {
  7. int [] array = new int [n];
  8. int [] fuelleArray = fuelleArray(array);
  9. int [] ergebnis = zaehleAb(fuelleArray);
  10. print(ergebnis);
  11. }
  12.  
  13. static int [] zaehleAb(int[] array) {
  14. int [] erg = new int [n];
  15.  
  16. for (int aktI = 0; aktI <array.length; aktI++) {
  17.  
  18. if (array[m-1]!=0) {
  19. erg [aktI] = array[m-1];
  20. array[m-1] = 0;
  21. }
  22.  
  23.  
  24.  
  25. }
  26.  
  27. return erg;
  28. }
  29.  
  30. static int[] fuelleArray(int[] array) {
  31. int sum = 1;
  32. int[]newArray = new int [n];
  33. for (int i = 0; i < newArray.length; i++) {
  34. newArray[i] = sum;
  35. sum++;
  36. }
  37. return newArray;
  38. }
  39.  
  40. static void print(int[] matrix) {
  41. IO.print("Ergebnis: ");
  42. for (int r = 0; r < matrix.length; r++) {
  43. System.out.print(matrix[r] + " ");
  44. }
  45. System.out.println();
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement