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.2KB

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