We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0fced0c commit 21f2cedCopy full SHA for 21f2ced
1 file changed
Exercise.java
@@ -1,6 +1,27 @@
1
+import java.util.Scanner;
2
+
3
public class Exercise {
4
5
public static void main(String[] args) {
- // 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);
26
}
27
0 commit comments