Those years, learn together Java 7-4

Source: Internet
Author: User


/**

* 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;&GT;=&NBSP;65&NBSP;&AMP;&AMP;&NBSP;NUMBER&NBSP;&LT;=&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

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.