Use Java to convert RMB in uppercase

Source: Internet
Author: User

I think it is impeccable.
Inspired by dracularking, I would like to express my gratitude and share my thoughts with you.

Public class rmbconvert {
Private Static string [] faceval = new string [] {"zero", "one", "two", "three", "Si ",
"Wu", "Lu", "Lu", "Wu", "Lu "};

Private Static string [] level = new string [] {"circle", "Pick", "weight "};

Public static void main (string [] Arg ){
Stringbuffer sb = new stringbuffer ();
Try {
Bufferedreader in = new bufferedreader (New inputstreamreader (
System. In ));
String S1 = in. Readline ();
For (INT I = 0; I <s1.length (); I ++ ){
Int digit = integer. valueof (s1.substring (I, I + 1). intvalue ();
SB. append (faceval [digit]);
}
String face = sb. Reverse (). tostring ();
Stringbuffer resultsb = new stringbuffer ();
For (INT I = 0; I <face. Length (); I ++ ){
// Weighted
If (I = 0 ){
Resultsb. append (level [0]);
}
Else {
// Processing tens of thousands of BITs
If (I + 4) % 8 = 0 ){
Resultsb. append (level [4]);
}
// Processing hundreds of millions of BITs
Else if (I % 8 = 0 ){
Resultsb. append (level [5]);
}
Else {
Resultsb. append (level [I % 4]);
}
}
// Nominal value
String temp = face. substring (I, I + 1 );
Resultsb. append (temp );
}

String result = resultsb. Reverse (). tostring ();


Result = result. replaceall ("Zero pick", "zero ");
Result = result. replaceall ("zero percentage", "zero ");
Result = result. replaceall ("zero percentage", "zero ");

Result = result. replaceall ("[zero] +", "zero ");

Result = result. replaceall ("", "");
Result = result. replaceall ("zero percentage", "minimum ");
Result = result. replaceall ("0 billion ");

System. Out. println (result + "whole ");
} Catch (exception e ){
E. printstacktrace ();
}
}
}
 

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.