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.

51 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 Uebung1 {
  6. private InputStream in;
  7. private PrintStream out;
  8. public Uebung1(InputStream in, PrintStream out) {
  9. this.in = in;
  10. this.out = out;
  11. }
  12. public static void main(String[] args) {
  13. new Uebung1(System.in, System.out).run();
  14. }
  15. private void run() {
  16. try (Scanner input = new Scanner(in)) {
  17. int nextInt = aquireUserInput(input, "enter an integer number: ");
  18. boolean isCheckPassed = checkNumber(nextInt);
  19. reportResult(String.format("number %d passed check: %b", nextInt,
  20. isCheckPassed));
  21. } ;
  22. }
  23. private void reportResult(String message) {
  24. out.print(message);
  25. }
  26. private boolean checkNumber(int nextInt) {
  27. for (int i = 2; i < nextInt; i++) {
  28. int result = nextInt % i;
  29. out.println(String.format(
  30. "input: %d, Schleifenvariable: %d, Ergebnis %d", nextInt, i,
  31. result));
  32. if (0 == result) {
  33. return false;
  34. }
  35. }
  36. return true;
  37. }
  38. private int aquireUserInput(Scanner input, String message) {
  39. reportResult(message);
  40. int nextInt = input.nextInt();
  41. return nextInt;
  42. }
  43. }