Java decomposition integer [10 hundred] (array case), java Array

Source: Internet
Author: User
Tags sca

Java decomposition integer [10 hundred] (array case), java Array

Calculate a single digit of several double digits, ten digits and hundreds of digits:

Int num = 53;

Int g = num % 10; // a bit
Int s = (num/10) % 10; // ten
Int B = (num/100); // bits

 

The following is a general case of sharding integers written in java. It is worth studying.

1 import java. util. outputs; // import the input library 2 class numbers 3 {4 public static void main (String [] args) 5 {6 // enter a maximum of billions of characters 7 // create an array, returns 8 String [] str = new String [] {"10", "100,000 ", "Millions", "tens of millions", "hundreds of millions", "billions", "tens of billions", "hundreds of billions"}; 9 10 systems. out. println ("enter a number:"); 11 bytes sca = new bytes (System. in); 12 13 // number of user input accepted 14 long sum = sca. nextInt (); // declare a long integer variable 15 long sum2 = sum; // separate and Judge positive and negative numbers 16 int a = 0; 17 18 for (int I = 0; I <32; I ++) 19 {20 // determine the number of user input digits 21 if (sum/10> 0) {// a single digit is greater than 0, positive number 22 sum = sum/10; 23 a ++; 24} else {25 break; 26} 27} 28 29 if (sum2 <10) // if it is negative 30 {31 long k = sum; 32 System. out. println ("this number has only one digit" + k); // 33 34} else {35 // splits the number of user inputs into 36 for (int I = 0; I <= a; I ++) 37 {38 if (I = 0) 39 {40 long c = sum2 % 10; // single digit 41 System. out. println ("the number of digits is:" + c); 42 43} else if (I <a) {44 // here we must convert the double value of this function; 45 long new1 = (long) Math. pow (10, I); 46 47 // parameter description: m is the number of required Parties, n is the power of 48 long B = sum2/new1 % 10; 49 System. out. println ("this number of" + str [I-1] + "Yes:" + B); 50 51} else {52 long new2 = (long) Math. pow (10, I); 53 long h = sum2/new2 % 10; 54 System. out. println ("this number of" + str [I-1] + "Yes:" + h); 55} 56} 57 58} 59 60} 61}

Momo said: the number of programming languages is the same. java is inherited from c, c ++, oc and other languages, so the fundamental principle remains unchanged.

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.