123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- public class Numbers {
-
- private int number;
-
- public static void main(String[] args) {
- for (int i = 1; i <= 200; i++) {
- if (isDivisibleBy(5, i)) {
- System.out.println(i + " ist durch " + 5 + " teilbar!");
- } else if (lastDigitIs(9, i)) {
- System.out.println(i + " endet auf " + 9);
- } else if (sumWithPredecessorIsDivisibleBy(3, i)) {
- System.out.println(i + " und " + (i - 1) + " addiert ergeben " + (2*i-1) + " und " + (2*i-1) + " ist durch " + 3 + " teilbar");
- }
- }
- }
-
- public static boolean isDivisibleBy( int divisor, int number) {
- if (number % divisor == 0 ) {
- return true;
- } else {
- return false;
- }
- }
-
- public static boolean lastDigitIs( int digit , int number) {
- if (number % 10 == digit) {
- return true;
- } else {
- return false;
- }
- }
-
- public static int sumWithPredecessor(int number) {
- return 2 * number -1;
- }
-
- public static boolean sumWithPredecessorIsDivisibleBy( int divisor, int number) {
- int s = sumWithPredecessor(number);
- if (isDivisibleBy(divisor, s)) {
- return true;
- } else {
- return false;
- }
- }
- }
|