Drawing histogram Java

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.