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