Java decomposition integer "1000" (array case)

Source: Internet
Author: User
Tags pow sca

One-digit, 10-digit, and hundred-digit two-digit number:

int num = 53;

int g = num% 10; Bit
int s = (NUM/10)% 10; Ten
int b = (num/100); Hundred

The following is a case of a general split integer written in Java worthy of study, the fun is endless oh

1 ImportJava.util.Scanner;//Import Input Library2 classnumbers3 {4      Public Static voidMain (string[] args)5     {6         //enter up to 1 billion bits7         //creates an array that traverses the corresponding number of bits in the output8string[] str =Newstring[]{"10-bit", "hundred", "thousand", "million-bit", "100,000-bit", "Million Dollar", "Chiwan", "million-bit", "1 billion-bit", "ranked", "Chi"};9 TenSystem.out.println ("Please enter a number:"); OneScanner SCA =NewScanner (system.in); A  -         //accept the number of user input -         Longsum = Sca.nextint ();//declaring a long integer variable the         Longsum2 = sum;//judging positive and negative numbers separately -         intA = 0;  -  -          for(inti = 0; i<32; i++ ) +         { -             //determine how many digits the user has entered +             if(Sum/10 > 0) {//Single digit greater than 0, positive Asum = SUM/10; ata++; -}Else{ -                  Break; -             } -         } -  in         if(Sum2 < 10)//if it's a negative number -         { to             LongK =sum; +SYSTEM.OUT.PRINTLN ("This number is only one digit is" +k);// -  the}Else{ *             //The number of user input is decomposed. $              for(inti = 0; I <= A; i++ )Panax Notoginseng             { -                 if(i==0) the                 { +                      Longc = sum2% 10;//Digit number ASYSTEM.OUT.PRINTLN ("The digits of this number are:" +c); the  +}Else if(I <a) { -                    //here is a strong turn to this function comes out of double; $                     LongNew1 = (Long) Math.pow (10, i);  $                           -                     //parameter Description: M is the number of the requesting party, N is the second-party number -                     Longb = Sum2/new1% 10; theSystem.out.println ("The +str[i-1]+ of this number" is: "+b); - Wuyi}Else{                 the                     LongNew2= (Long) Math.pow (10, i); -                     Longh = sum2/new2% 10; WuSystem.out.println ("The +str[i-1]+ of this number" is: "+h); -                  } About             } $          -         } -  -     } A}

Mo Mo said: The programming language between how many are interlinked, original aim, Java is inherited in C,c++,oc and other languages, so the fundamental principle is unchanged.

Java decomposition integer "1000" (array case)

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.