Created
November 21, 2018 21:34
-
-
Save corusm/031e0737cc4467e01223f44974ab473e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
Scanner keyboard = new Scanner(System.in); | |
System.out.println("Text eingeben..."); | |
String text = keyboard.nextLine().toLowerCase(); | |
char[] chartext = text.toCharArray(); | |
char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray(); | |
int[] verteilung = new int[26]; | |
double[] prozent = new double[26]; | |
for (int i = 0; i < 26; i++) { | |
for (int a = 0; a < chartext.length; a++) { | |
if (alphabet[i] == chartext[a]) { | |
verteilung[i]++; | |
} | |
} | |
} | |
for (int d = 0; d < 26; d++) { | |
if (verteilung[d] > 0) { | |
double temp = verteilung[d]; | |
prozent[d] = (temp / chartext.length) * 100; | |
} | |
} | |
for (int b = 0; b < 26; b++) { | |
if (verteilung[b] > 0) { | |
System.out.println(alphabet[b] + " = " + verteilung[b] + " (" + Math.round(100.0 * prozent[b]) / 100.0 + "%)"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment