Sample input:
The QUICK BROWN FOX JUMPED over the LAZY DOG.
This is a EXAMPLE to TEST for YOUR
Histogram program.
Hello!
Sample output:
*
*
* *
* * * *
* * * *
* * * * * *
* * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * *
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
The title means to enter a uppercase string from the command line, and to draw the frequency of the occurrence of a character.
Import Java.io.bufferedreader;import java.io.ioexception;import java.io.inputstreamreader;import java.util.Arrays; public class Main {public static void main (string[] args) throws NumberFormatException, IOException { BufferedReader read = new BufferedReader (new InputStreamReader (system.in)); Int[] A = new int[26]; int tt; for (int i = 0; i < 4; i++) {String str = read.readline (); for (int j = 0; J < Str.length (); j + +) {tt = Str.charat (j)-' A '; if (TT >= 0 && tt <=) {a[tt]++; }}} int max = 0; for (int i = 0; i < i++) {if (A[i] > max) {max = a[i]; }} char[][] c = new Char[max + 1][51]; for (int i = 0; i < Max + 1; i++) {Arrays.fill (C[i], "); } for (int i = 0; i <; i++) {int h = a[i]; For(int j = 0; J < H; j + +) {c[max-1-j][i * 2] = ' * '; }} for (int i = 0; i < i++) {C[max][i * 2] = (char) (' A ' + i); } for (int i = 0; i < Max + 1; i++) {String str = string.valueof (c[i]); while (Str.endswith ("")) {str = str.substring (0, Str.length ()-1); } System.out.println (str); } }
Drawing histogram Java