|
3 | 3 | public class Exercise { |
4 | 4 |
|
5 | 5 | public static void main(String[] args) { |
6 | | - @SuppressWarnings("resource") |
7 | | - Scanner sc = new Scanner(System.in); |
8 | | - |
9 | | - System.out.print("Gib bitte die erste Zeichenkette ein: "); |
10 | | - String input1 = sc.nextLine(); |
11 | | - |
12 | | - System.out.print("Gib bitte die zweite Zeichenkette ein: "); |
13 | | - String input2 = sc.nextLine(); |
14 | | - |
15 | | - boolean identical = true; |
16 | | - |
17 | | - if (input1.length() != input2.length()) { |
18 | | - identical = false; |
19 | | - } |
20 | | - |
21 | | - if (identical) { |
22 | | - for (int i = 0; i < input1.length(); i++) { |
23 | | - char char1 = input1.charAt(i); |
24 | | - char char2 = input2.charAt(i); |
25 | | - char1 = Character.toUpperCase(char1); |
26 | | - char2 = Character.toUpperCase(char2); |
27 | | - if (char1 != char2) { |
28 | | - identical = false; |
29 | | - break; |
30 | | - } |
31 | | - } |
32 | | - } |
33 | | - |
34 | | - System.out.println(identical ? "Die beiden Zeichenketten sind identisch" |
35 | | - : "Die beiden Zeichenketten sind nicht identisch"); |
36 | | - |
| 6 | + @SuppressWarnings("resource") |
| 7 | + Scanner sc = new Scanner(System.in); |
| 8 | + |
| 9 | + System.out.print("Gib bitte die erste Zeichenkette ein: "); |
| 10 | + String input1 = sc.nextLine(); |
| 11 | + |
| 12 | + System.out.print("Gib bitte die zweite Zeichenkette ein: "); |
| 13 | + String input2 = sc.nextLine(); |
| 14 | + |
| 15 | + boolean identical = true; |
| 16 | + |
| 17 | + if (input1.length() != input2.length()) { |
| 18 | + identical = false; |
| 19 | + } |
| 20 | + |
| 21 | + if (identical) { |
| 22 | + for (int i = 0; i < input1.length(); i++) { |
| 23 | + char char1 = input1.charAt(i); |
| 24 | + char char2 = input2.charAt(i); |
| 25 | + char1 = Character.toUpperCase(char1); |
| 26 | + char2 = Character.toUpperCase(char2); |
| 27 | + if (char1 != char2) { |
| 28 | + identical = false; |
| 29 | + break; |
| 30 | + } |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + System.out.println( |
| 35 | + identical |
| 36 | + ? "Die beiden Zeichenketten sind identisch" |
| 37 | + : "Die beiden Zeichenketten sind nicht identisch"); |
37 | 38 | } |
38 | 39 | } |
0 commit comments