From 06d8162bc872d91477a043784c64b2b13eec7166 Mon Sep 17 00:00:00 2001 From: "farzad.h" Date: Mon, 8 Apr 2024 11:15:55 +0200 Subject: [PATCH] aufgabe 2.2 erledigt --- Pr2_Uebung2/src/Console.java | 23 +++++++++++++++++++++++ Pr2_Uebung2/src/DemoConsole.java | 21 +++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 Pr2_Uebung2/src/Console.java create mode 100644 Pr2_Uebung2/src/DemoConsole.java diff --git a/Pr2_Uebung2/src/Console.java b/Pr2_Uebung2/src/Console.java new file mode 100644 index 0000000..0bfa310 --- /dev/null +++ b/Pr2_Uebung2/src/Console.java @@ -0,0 +1,23 @@ +import java.util.Scanner; + +public class Console { + + Scanner input = new Scanner(System.in); + + public String readString() { + String text = input.nextLine(); + return text; + } + + public char[] readCharArray() { + String text = input.nextLine(); + char[] cText = text.toCharArray(); + + return cText; + } + + public boolean readBoolean() { + boolean bText = input.nextBoolean(); + return bText; + } +} diff --git a/Pr2_Uebung2/src/DemoConsole.java b/Pr2_Uebung2/src/DemoConsole.java new file mode 100644 index 0000000..9950eee --- /dev/null +++ b/Pr2_Uebung2/src/DemoConsole.java @@ -0,0 +1,21 @@ + +public class DemoConsole { + public static void main(String[] args) throws Exception { + + Console Console = new Console(); + System.out.println("Text eingeben: "); + String text = Console.readString(); + System.out.println("Gelesener Text: " + text); + + System.out.println("Text eingeben: "); + char[] ca = Console.readCharArray(); + System.out.println("Gelesenes char-Feld: "); + for (char celement : ca) + System.out.print(celement); + System.out.println(); + + System.out.println("Boolean eingeben: "); + boolean b = Console.readBoolean(); + System.out.println("Gelesener Wert: " + b); + } +}