Statement Exercises 2

Source: Internet
Author: User

Give a positive integer not more than 5 bits, ask: First, it is a number of digits, second, the reverse print out the numbers.

1Scanner sc =NewScanner (;2System.out.println ("Please enter a positive integer with no more than 5 bits:");3         intnum =sc.nextint ();4         if(Num > 99999| | Num<0) {5SYSTEM.OUT.PRINTLN ("You entered the wrong number, please re-enter!") ");6}Else {7Integer s =NewInteger (num);8String str =s.tostring ();9SYSTEM.OUT.PRINTLN ("You have entered a" + str.length () + "bit number.) ");TenSYSTEM.OUT.PRINTLN ("Input positive integer reverse output:"); One              for(inti = Str.length ()-1; I >= 0; i--) { A System.out.print (Str.charat (i)); -             } -}


Statement Exercises 2

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: 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.