Prak test gi
This commit is contained in:
parent
6547a490d8
commit
87e8a53f9e
@ -2,31 +2,64 @@ package Prak1;
|
||||
|
||||
public class Zahlenfilter {
|
||||
|
||||
public static void main(String[] args){
|
||||
filter();
|
||||
public static void main(String[] args) {
|
||||
Filter filter1 = new Filter();
|
||||
filter1.zahlenfiltern();
|
||||
}
|
||||
}
|
||||
|
||||
class Zahl {
|
||||
|
||||
private int value;
|
||||
|
||||
public Zahl(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public boolean istDurchFuenfTeilbar() {
|
||||
return value % 5 == 0;
|
||||
}
|
||||
|
||||
public boolean endetAufNeun() {
|
||||
return value % 10 == 9;
|
||||
}
|
||||
|
||||
public int addieren(Zahl other) {
|
||||
return this.value + other.getValue();
|
||||
}
|
||||
|
||||
public boolean istDurchDreiTeilbar() {
|
||||
return (value + (value - 1)) % 3 == 0;
|
||||
}
|
||||
}
|
||||
|
||||
class Filter {
|
||||
|
||||
public void zahlenfiltern() {
|
||||
Zahl zahl;
|
||||
Zahl vorherigeZahl = new Zahl(0);
|
||||
for (int i = 0; i <= 300; i++) {
|
||||
zahl = new Zahl(i);
|
||||
if (zahl.istDurchFuenfTeilbar()) {
|
||||
System.out.println(i + " ist durch 5 teilbar");
|
||||
} else {
|
||||
if (zahl.endetAufNeun()) {
|
||||
System.out.println(i + " endet auf 9");
|
||||
} else {
|
||||
int summe = zahl.addieren(vorherigeZahl);
|
||||
if (zahl.istDurchDreiTeilbar()) {
|
||||
System.out.println(i + " und " + (i - 1) + " addiert ergeben " + summe + " und " + summe + " ist durch 3 teilbar");
|
||||
} else {
|
||||
System.out.println(i + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
vorherigeZahl = zahl;
|
||||
}
|
||||
}
|
||||
|
||||
public static void filter(){
|
||||
int i;
|
||||
int x;
|
||||
for( i = 0; i <= 200; i++) {
|
||||
if( i % 5 == 0 ){
|
||||
System.out.println( i + " ist durch 5 teilbar");
|
||||
} else{
|
||||
if(i % 10 == 9){
|
||||
System.out.println( i + " endet auf 9");
|
||||
} else{
|
||||
x = i + (i-1);
|
||||
if( x % 3 == 0){
|
||||
System.out.println(i + " und " + (i-1) + " addiert ergeben "+ x + " und " + x + " ist durch 3 teilbar");
|
||||
} else{
|
||||
System.out.println(i+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,10 @@ package Prak1;
|
||||
public class Zahlenfilter_save {
|
||||
|
||||
public static void main(String[] args){
|
||||
filter();
|
||||
}
|
||||
|
||||
public static void filter(){
|
||||
int i;
|
||||
int x;
|
||||
for( i = 0; i <= 200; i++) {
|
||||
@ -16,11 +20,13 @@ public class Zahlenfilter_save {
|
||||
if( x % 3 == 0){
|
||||
System.out.println(i + " und " + (i-1) + " addiert ergeben "+ x + " und " + x + " ist durch 3 teilbar");
|
||||
} else{
|
||||
System.out.println(i);
|
||||
System.out.println(i+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user