File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed
Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change 1+ import java .util .Scanner ;
2+
13public 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}
You can’t perform that action at this time.
0 commit comments