UE14
This commit is contained in:
@@ -1,16 +1,47 @@
|
||||
package UE14_130225_Streams;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class UE14_Streams {
|
||||
public static void main(String[] args) {
|
||||
// zahlenreihen();
|
||||
// printFolgeOhne3(1);
|
||||
// printFolgeOhne3(5);
|
||||
// printFolgeOhne3(10);
|
||||
// printFolgeOhne3(20);
|
||||
wuerfelStatistik(6);
|
||||
zahlenreihen();
|
||||
|
||||
printFolgeOhne3(1);
|
||||
printFolgeOhne3(5);
|
||||
printFolgeOhne3(10);
|
||||
printFolgeOhne3(20);
|
||||
|
||||
for (int i = 1; i <= 6; i++) wuerfelStatistik(i);
|
||||
|
||||
for (int i = 0; i <= 100; i++) alleTeiler(i);
|
||||
|
||||
for (int i = 0; i <= 100; i++)
|
||||
if (istPrimzahl(i)) System.out.println(i + ": is a Prime Number");
|
||||
else System.out.println(i + ": is NOT Prime Number");
|
||||
|
||||
for (int i = 0; i <= 10; i++) System.out.println(i + ": " + gaussSumme(i));
|
||||
|
||||
verticalString("Hallo");
|
||||
verticalString("Hallo!!!");
|
||||
verticalString("a(&\t/'?%\n§''%Z??/§$%");
|
||||
|
||||
mitStern("Hallo");
|
||||
System.out.println();
|
||||
mitStern("Hallo!!!");
|
||||
System.out.println();
|
||||
mitStern("a(&/'?%§''%Z??/§$%");
|
||||
System.out.println();
|
||||
|
||||
deleteBlanks("Hallo Welt wie gehts");
|
||||
System.out.println();
|
||||
|
||||
System.out.println(enthaeltZiffern("Hallo 3AI"));
|
||||
System.out.println(enthaeltZiffern("Hallo Welt"));
|
||||
System.out.println(enthaeltZiffern("0"));
|
||||
System.out.println(enthaeltZiffern("A"));
|
||||
System.out.println(enthaeltZiffern(""));
|
||||
}
|
||||
|
||||
public static void zahlenreihen() {
|
||||
@@ -33,25 +64,35 @@ public class UE14_Streams {
|
||||
}
|
||||
|
||||
public static void wuerfelStatistik(int augenzahl) {
|
||||
System.out.println(augenzahl + ": " + new Random().ints(1000, 1, 7).filter(n -> n == augenzahl).count());
|
||||
}
|
||||
|
||||
public static void alleTeiler(int z) {
|
||||
System.out.println(z + ": " + IntStream.rangeClosed(1, z).filter(n -> z % n == 0).mapToObj(String::valueOf).reduce((a, b) -> a + ", " + b).orElse(""));
|
||||
}
|
||||
|
||||
public static boolean istPrimzahl(int z) {
|
||||
return true;
|
||||
// return z > 1 && IntStream.rangeClosed(2, z).filter(n -> z % n == 0).count() == 1;
|
||||
return z > 1 && IntStream.rangeClosed(2, (int) Math.sqrt(z)).allMatch(n -> z % n != 0); // More Efficient (from 10-12ms to 5-8ms)
|
||||
}
|
||||
|
||||
public static int gaussSumme(int n) {
|
||||
return 0;
|
||||
return IntStream.rangeClosed(1, n).sum();
|
||||
}
|
||||
|
||||
public static void verticalString(String s) {
|
||||
s.chars().forEach(c -> System.out.println((char) c));
|
||||
}
|
||||
|
||||
public static void mitStern(String s) {
|
||||
s.chars().forEach(c -> System.out.print((char) c + "*"));
|
||||
}
|
||||
|
||||
public static void deleteBlanks(String s1) {
|
||||
s1.chars().filter(c -> c != ' ').forEach(c -> System.out.print((char) c));
|
||||
}
|
||||
|
||||
public static boolean enthaeltZiffern(String s) {
|
||||
return s.chars().filter(Character::isDigit).findAny().isPresent();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user