Sabina Grisi
1 year ago
3 changed files with 116 additions and 0 deletions
-
17Lerntagebuch.md
-
51Uebung1.java
-
48Uebung2.java
@ -0,0 +1,51 @@ |
|||||
|
package de.edu.hsfulda.pmut.debugging; |
||||
|
|
||||
|
import java.io.InputStream; |
||||
|
import java.io.PrintStream; |
||||
|
import java.util.Scanner; |
||||
|
|
||||
|
public class Uebung1 { |
||||
|
private InputStream in; |
||||
|
private PrintStream out; |
||||
|
|
||||
|
public Uebung1(InputStream in, PrintStream out) { |
||||
|
this.in = in; |
||||
|
this.out = out; |
||||
|
} |
||||
|
|
||||
|
public static void main(String[] args) { |
||||
|
new Uebung1(System.in, System.out).run(); |
||||
|
} |
||||
|
|
||||
|
private void run() { |
||||
|
try (Scanner input = new Scanner(in)) { |
||||
|
int nextInt = aquireUserInput(input, "enter an integer number: "); |
||||
|
boolean isCheckPassed = checkNumber(nextInt); |
||||
|
reportResult(String.format("number %d passed check: %b", nextInt, |
||||
|
isCheckPassed)); |
||||
|
} ; |
||||
|
} |
||||
|
|
||||
|
private void reportResult(String message) { |
||||
|
out.print(message); |
||||
|
} |
||||
|
|
||||
|
private boolean checkNumber(int nextInt) { |
||||
|
for (int i = 2; i < nextInt; i++) { |
||||
|
int result = nextInt % i; |
||||
|
out.println(String.format( |
||||
|
"input: %d, Schleifenvariable: %d, Ergebnis %d", nextInt, i, |
||||
|
result)); |
||||
|
if (0 == result) { |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
private int aquireUserInput(Scanner input, String message) { |
||||
|
reportResult(message); |
||||
|
int nextInt = input.nextInt(); |
||||
|
return nextInt; |
||||
|
} |
||||
|
} |
@ -0,0 +1,48 @@ |
|||||
|
//package de.edu.hsfulda.pmut.debugging; |
||||
|
|
||||
|
import java.io.InputStream; |
||||
|
import java.io.PrintStream; |
||||
|
import java.util.Scanner; |
||||
|
|
||||
|
public class Uebung2 { |
||||
|
private InputStream in; |
||||
|
private PrintStream out; |
||||
|
private int count = 2; |
||||
|
public Uebung2(InputStream in, PrintStream out) { |
||||
|
this.in = in; |
||||
|
this.out = out; |
||||
|
} |
||||
|
|
||||
|
public static void main(String[] args) { |
||||
|
new Uebung2(System.in, System.out).run(); |
||||
|
} |
||||
|
|
||||
|
private void run() { |
||||
|
try (Scanner input = new Scanner(in)) { |
||||
|
int nextInt = aquireUserInput(input, "enter an integer number: "); |
||||
|
boolean isCheckPassed = checkNumber(nextInt); |
||||
|
reportResult(String.format("number %d passed check: %b", nextInt, |
||||
|
isCheckPassed)); |
||||
|
} ; |
||||
|
} |
||||
|
|
||||
|
private void reportResult(String message) { |
||||
|
out.print(message); |
||||
|
} |
||||
|
|
||||
|
private boolean checkNumber(int nextInt) { |
||||
|
if (count > nextInt) |
||||
|
return true; |
||||
|
if (nextInt % count == 0) |
||||
|
return false; |
||||
|
nextInt = nextInt - (nextInt / count); |
||||
|
count++; |
||||
|
return checkNumber(nextInt); |
||||
|
} |
||||
|
|
||||
|
private int aquireUserInput(Scanner input, String message) { |
||||
|
reportResult(message); |
||||
|
int nextInt = input.nextInt(); |
||||
|
return nextInt; |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue