geändert am 21.11.2023 um 15:27

This commit is contained in:
leonmcfly
2023-11-21 15:27:57 +01:00
parent 15d7358bfe
commit ee07f5e279
3 changed files with 111 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
package Praktikum03;
public class Zahlenfilter {
public static void main(String[] args) {
int upper_limit = 200;
if (args.length > 0)
upper_limit = Integer.parseInt(args[0]);
Zahlenfilter z = new Zahlenfilter(upper_limit);
z.printNumber();
}
private int boundary;
private Zahlenfilter(int limit){
boundary = limit;
}
private void printNumber(){
for(int i = 1; i <=boundary; i++){
if(filter(i))
System.out.println(i);
}
}
public static boolean filter(int i){
return !(checkDivisibleBy5(i) || checkEndsWith9(i) || checkSumDivisibleBy3(i, i-1));
}
public static boolean checkDivisibleBy5(int i) {
return(i % 5 == 0);
}
public static boolean checkEndsWith9(int i){
return(i % 10 == 9);
}
public static boolean checkSumDivisibleBy3(int i, int j){
return((i+j) % 3 == 0);
}
}