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.

48 lines
1.1 KiB

  1. //package de.edu.hsfulda.pmut.debugging;
  2. import java.io.InputStream;
  3. import java.io.PrintStream;
  4. import java.util.Scanner;
  5. public class Uebung2 {
  6. private InputStream in;
  7. private PrintStream out;
  8. private int count = 2;
  9. public Uebung2(InputStream in, PrintStream out) {
  10. this.in = in;
  11. this.out = out;
  12. }
  13. public static void main(String[] args) {
  14. new Uebung2(System.in, System.out).run();
  15. }
  16. private void run() {
  17. try (Scanner input = new Scanner(in)) {
  18. int nextInt = aquireUserInput(input, "enter an integer number: ");
  19. boolean isCheckPassed = checkNumber(nextInt);
  20. reportResult(String.format("number %d passed check: %b", nextInt,
  21. isCheckPassed));
  22. } ;
  23. }
  24. private void reportResult(String message) {
  25. out.print(message);
  26. }
  27. private boolean checkNumber(int nextInt) {
  28. if (count > nextInt)
  29. return true;
  30. if (nextInt % count == 0)
  31. return false;
  32. nextInt = nextInt - (nextInt / count);
  33. count++;
  34. return checkNumber(nextInt);
  35. }
  36. private int aquireUserInput(Scanner input, String message) {
  37. reportResult(message);
  38. int nextInt = input.nextInt();
  39. return nextInt;
  40. }
  41. }