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)