Output 9 by 9 multiplication tables and achieve 0-9 occurrences of each number and print out

Source: Internet
Author: User


Output 99 multiplication table


Import Java.util.hashmap;import java.util.iterator;import Java.util.map;import Java.util.map.entry;import Java.util.set;public class Multiplicationtable {public static void main (string[] args) {//defines a string cache for storing product results StringBuffer                        SB = new StringBuffer ();//output multiplication table for (int i=1; i<=9; i++) {for (int j=1; j<=i; J + +) {                     To make alignment adjustments, start with the second column, and if the result length is single digit, fill in the blanks if (J ==2 && string.valueof (i*j). Length () = = 1) {                                        System.out.print (j + "*" + i + "=" + I*j + "");                Put the accumulation in SB sb.append (I*J);                    } else {System.out.print (j + "*" + i + "=" + I*j + ");                Sb.append (I*J);        }}//end of line, line wrap Operation System.out.println (); }//define map, hold characters and the number of occurrences map<character, integer> map = new Hashmap<character, Integer        > (); STring str = sb.tostring ();            Traverses str, storing characters and their occurrences in map for (int i=0; i<str.length (); i++) {Character num = Str.charat (i);            if (null! = Map.get (num)) {map.put (num, map.get (num) + 1);            } else {map.put (num, 1);         }}//Get Entry result set and traverse output Set<entry<character, integer>> entryset = Map.entryset ();        Iterator<entry<character, integer>> it = Entryset.iterator ();            while (It.hasnext ()) {entry<character, integer> Entry = It.next ();        System.out.println (Entry.getkey () + "" + Entry.getvalue ()); }}}


Output 9 by 9 multiplication tables and achieve 0-9 occurrences of each number and print out

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.