src/Praktikum3/ZahlenFilter.java gelöscht
This commit is contained in:
parent
ca49d5e8d8
commit
ee97555e8a
@ -1,49 +0,0 @@
|
||||
package Praktikum3;
|
||||
|
||||
public class ZahlenFilter {
|
||||
public void durchlaufenUndPruefen(int maxZahl) {
|
||||
for (int zahl = 1; zahl <= maxZahl; zahl++) {
|
||||
if (filter(zahl)){
|
||||
System.out.println(zahl + " erfüllt keins der Kriterien ");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public static boolean filter(int zahl){
|
||||
return (!istDurch5Teilbar(zahl) && !endetAuf9(zahl) && !istDurch3TeilbarMitVorgaenger(zahl));
|
||||
|
||||
|
||||
}
|
||||
public static boolean istDurch5Teilbar(int zahl) {
|
||||
return zahl % 5 == 0;
|
||||
}
|
||||
|
||||
public static boolean endetAuf9(int zahl) {
|
||||
String zahlAlsString = Integer.toString(zahl);
|
||||
char letzteZiffer = zahlAlsString.charAt(zahlAlsString.length() - 1);
|
||||
return letzteZiffer == '9';
|
||||
}
|
||||
|
||||
public static boolean istDurch3TeilbarMitVorgaenger(int zahl) {
|
||||
if (zahl > 1) {
|
||||
int vorgaenger = zahl - 1;
|
||||
int summe = zahl + vorgaenger;
|
||||
return summe % 3 == 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
int maxZahl = 200; // Standardwert
|
||||
if (args.length > 0) {
|
||||
try {
|
||||
maxZahl = Integer.parseInt(args[0]);
|
||||
} catch (NumberFormatException e) {
|
||||
System.out.println("Ungültiger Parameter. Verwende Standardwert 200.");
|
||||
}
|
||||
}
|
||||
|
||||
ZahlenFilter pruefung = new ZahlenFilter();
|
||||
pruefung.durchlaufenUndPruefen(maxZahl);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user