Changeset 397 in Java_Quellcode_SOOP_Vorlesung
- Timestamp:
- Dec 5, 2017, 9:36:04 AM (7 years ago)
- Location:
- rekursion
- Files:
-
- 1 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
rekursion/Rekursion.java
r396 r397 1 1 package eu.hsrw.tr.prog.vl.rekursion; 2 3 import java.util.Arrays; 2 4 3 5 /** … … 100 102 return istPalindrom(s.substring(1, s.length() - 1)); 101 103 } 104 105 public static int minRekursiv(int[] a, int pos) { 106 if (pos == a.length - 1) { 107 return a[pos]; 108 } 109 int minRest = minRekursiv(a, pos + 1); 110 if (minRest < a[pos]) { 111 return minRest; 112 } 113 return a[pos]; 114 } 115 116 public static int min(int[] a) { 117 return minRekursiv(a, 0); 118 } 119 120 public static int summeRekursiv(int[] a, int pos) { 121 if (pos == a.length - 1) { 122 return a[pos]; 123 } 124 return a[pos] + summeRekursiv(a, pos + 1); 125 } 126 127 public static int summe(int[] a) { 128 return summeRekursiv(a, 0); 129 } 130 131 public static int summe2(int[] a) { 132 if (a.length == 0) { 133 return 0; 134 } 135 return a[0] + summe2(Arrays.copyOfRange(a, 1, a.length)); 136 } 137 138 139 public static void main(String[] args) { 140 141 tuermeVonHanoi(4, 'A', 'B', 'C'); 142 143 int[] a = {-9, 2, 7, -4, 9, 0, 0, 6, 3, 5, 2, 7, -6, 9}; 144 145 System.out.println(summe2(a)); 146 /* 147 System.out.println(ggt(60, 18)); 148 /* 149 System.out.println(istPalindrom("Otto")); 150 System.out.println(istPalindrom("")); 151 System.out.println(istPalindrom("hdsjkhdfk")); 152 /* 153 System.out.println(fibonacci(45)); 154 /**/ 155 } 156 102 157 }
Note: See TracChangeset
for help on using the changeset viewer.