Repository zur Vorlesung Prog3
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Numbers.java 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. public class Numbers {
  2. private int number;
  3. public static void main(String[] args) {
  4. for (int i = 1; i <= 200; i++) {
  5. if (isDivisibleBy(5, i)) {
  6. System.out.println(i + " ist durch " + 5 + " teilbar!");
  7. } else if (lastDigitIs(9, i)) {
  8. System.out.println(i + " endet auf " + 9);
  9. } else if (sumWithPredecessorIsDivisibleBy(3, i)) {
  10. System.out.println(i + " und " + (i - 1) + " addiert ergeben " + (2*i-1) + " und " + (2*i-1) + " ist durch " + 3 + " teilbar");
  11. }
  12. }
  13. }
  14. public static boolean isDivisibleBy( int divisor, int number) {
  15. if (number % divisor == 0 ) {
  16. return true;
  17. } else {
  18. return false;
  19. }
  20. }
  21. public static boolean lastDigitIs( int digit , int number) {
  22. if (number % 10 == digit) {
  23. return true;
  24. } else {
  25. return false;
  26. }
  27. }
  28. public static int sumWithPredecessor(int number) {
  29. return 2 * number -1;
  30. }
  31. public static boolean sumWithPredecessorIsDivisibleBy( int divisor, int number) {
  32. int s = sumWithPredecessor(number);
  33. if (isDivisibleBy(divisor, s)) {
  34. return true;
  35. } else {
  36. return false;
  37. }
  38. }
  39. }