/**
* 7-4
* Write a exercise class that contains the following methods
* 1> Statistics (Object arc[]) method:
* Count the number of occurrences of each letter (regardless of case) relative to the total number of letters,
* Print Show this ratio
* 2> Sort (Object arc[]) method:
* Sort the given array.
* Programmatically create an object of the exercise class,
* Receive user input from the main method in English text,
* and deposit it into the newly created object.
* Display the output result by calling the object method.
*/
Import java.util.arrays;import java.util.scanner; public class test{public static void main (String[] args) {Scanner read = new scanner (System.in) ; System.out.println ("Enter a paragraph of English text");//char[] text = new char[100];//int i = 0;// while (Read.nextint () != -1)//text[i++] = (char) read.nextint (); String text = read.next (); Exercise exercise = new exercise (); Exercise. Statistics (text); Exercise.mysort (text);}} Class exercise{void statistics (string text) {char word[] = new char[256];for (int i = 0; i < 256; i++) word[i]=0;for (int i = 0; i < text.length (); i++) {Int number = text.charat (i);if ( NUMBER&NBSP;>=&NBSP;65&NBSP;&&&NBSP;NUMBER&NBSP;<=&NBSP;90) Number += 32;++word[number];} for (int i = 0; i < 256; i++) if (word[i] > 0) System.out.println (char) i + " occupies a ratio of " + (double) word[i]/text.length ());} void mysort (String text) {char[] texts = new char[text.length ()];for ( int i = 0; i < texts.length; i++) Texts[i] = text.charat (i); Arrays.sort (texts);for (int i = 0; i < texts.length; i++) System.out.print (texts[i] + " ");}}
This article is from the "hacker" blog, make sure to keep this source http://anglecode.blog.51cto.com/5628271/1619868
Those years, learn together Java 7-4