Java indexof, BigDecimal, string substitution

Source: Internet
Author: User

Self-summary, what needs to be corrected to make up for the place, please point out, grateful!

This paper summarizes the usage of indexof ,bigdecimal multiplication, shift operation ,formatted output of decimal, string substitution

On the code:

Test class Test.java

 PackageCom.core;Importjava.io.IOException;ImportJava.math.BigDecimal;ImportJava.text.DecimalFormat;ImportJava.util.regex.Matcher;ImportJava.util.regex.Pattern; Public classTest { Public Static voidMain (string[] args)throwsIOException {//IndexOf returns the subscript position of the character to be queried in the current string, if there is no return-1String cname = "Nicolas Cage"; System.out.println (Cname.indexof (Provence)); String ename= "Nicolas Cage"; System.out.println (Ename.indexof (" ")); System.out.println (Ename.indexof ("B")); //BigDecimal is generally used in platforms with money trading, and float and double cannot guarantee higher numerical accuracyBigDecimal B =NewBigDecimal ("0.41"); Longm = b.multiply (NewBigDecimal ("+")). Longvalue ();//0.41*300b =NewBigDecimal ("0.09"); Longs = b.movepointright (2). Longvalue ();//0.09 decimal point shifted right two bitString result = long.valueof (M-s). toString ();                SYSTEM.OUT.PRINTLN (result); //DecimalFormat formatted outputDecimalFormat DF =NewDecimalFormat ("#0.00"); DecimalFormat DF1=NewDecimalFormat ("#.00"); Double percent= 0.965;        SYSTEM.OUT.PRINTLN (Df.format (percent));                SYSTEM.OUT.PRINTLN (Df1.format (percent)); //replace characters in a stringString name = "Sensitive Vocabulary"; Pattern P= Pattern.compile ("Sensitive"); Matcher M1=P.matcher (name); if(M1.find ()) {System.out.println (M1.replaceall (Harmonious)); }    }}

Printing results:

37-11140.96. Harmony Vocabulary

Java indexof, BigDecimal, string substitution

Related Article

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.