Browse Source

mein zweiter commit

remotes/origin/HEAD
Sabina Grisi 1 year ago
parent
commit
ea95781ebc
  1. 3
      Lerntagebuch.md
  2. 51
      Uebung1.java
  3. 48
      Uebung2.java

3
Lerntagebuch.md

@ -18,7 +18,7 @@
### Kritik
- Mir gefiel die langsame und freundliche Art, wie sie die Dinge erklärten.
---
## SU 02 (03.11.2023)
@ -34,6 +34,7 @@
### Wiederholung
- Die Imperative Programmierung ist so, als würdest du der Computer Schritt für Schritt Anweisungen geben. Es ist, als würdest du ihm genau sagen, was er in jedem Moment tun soll. Also, anstatt ihm zu sagen "löse dieses Problem", sagst du ihm "nimm diese Werte, mach diese Operation, speichere dann das Ergebnis".
---
## SU 03 (10.11.2023)

51
Uebung1.java

@ -1,51 +0,0 @@
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;
}
}

48
Uebung2.java

@ -1,48 +0,0 @@
//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;
}
}
Loading…
Cancel
Save