Skip to content

Commit dd5accd

Browse files
committed
implement soluton
1 parent 8e55ee8 commit dd5accd

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

Exercise.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
1+
import java.util.Scanner;
2+
13
public class Exercise {
24

35
public static void main(String[] args) {
4-
// implement exercise here
6+
@SuppressWarnings("resource")
7+
Scanner sc = new Scanner(System.in);
8+
9+
System.out.print("Gib bitte eine Zeichenkette ein: ");
10+
String text = sc.nextLine();
11+
12+
System.out.print("Gib bitte das zu analysierende Zeichen ein: ");
13+
char token = sc.next().charAt(0);
14+
15+
int count = 0;
16+
for (int i = 0; i < text.length(); i++) {
17+
if (text.charAt(i) == token) {
18+
count++;
19+
}
20+
}
21+
22+
double percentage = count * 100 / text.length();
23+
24+
System.out.printf("Absoluter Anteil: %d%n", count);
25+
System.out.printf("Prozentualer Anteil: %.2f%%%n", percentage);
526
}
627
}

0 commit comments

Comments
 (0)