Java Fundamentals Exercise given a positive integer m, the number of bits of m, each digit is printed, and then the numbers are printed in reverse order.

Source: Internet
Author: User

Requirements:m is defined as a property of the class, the constructor must be defined as m assignment, and when m is greater than 99999 , the output error message " the number is too large"and is no longer executed.

 Public classT {Private intm;  PublicTintm) {Super();  This. m =m; }     Public intGetm () {returnm; }     Public voidSetm (intm) { This. m =m; }     Public voidM () {if(m>99999) {System.out.println ("The number is too large"); }        Else{String str=m+ ""; System.out.println ("A total of" +str.length () + "bit"); System.out.println ("Each digit is:");  for(intI=0;i<str.length (); i++) {System.out.print (Str.charat (i)+" "); } System.out.println ("\ n Reverse");  for(intI=str.length () -1;i>=0;i--) {System.out.print (Str.charat (i)); }                    }    }     Public Static voidMain (string[] args) {T m=NewT (85412);            M.M (); }}

Java Fundamentals Exercise given a positive integer m, the number of bits of m, each digit is printed, and then the numbers are printed in reverse order.

Related Article

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.