Input:
Format 1:scanner sc = new Scanner (system.in);
Format 2:scanner sc = new Scanner (new Bufferedinputstream (system.in));
When the amount of data is large, format 2 is faster.
Split method:
String str = Scanner.next ();
string[] Date = Str.split ("/");
System. out. println (date[0]+ "year" +date[1]+ "month" +date[2]+ "Day");
DecimalFormat
NumberFormat
Keep the number of decimal place!!
Bigdecimal.setscale (2,BIGDECIMAL.ROUND_HALF_UP);
Sub-string:
String ss = "Wo Ai Zhou";
System. out. println (ss.substring (3,7));
Intercept substring from 3rd to 7th (starting from 0, 7th digit not counted)
The result is: Ai Z
High accuracy:
BigInteger and BigDecimal are places where Java has a big advantage as a tool for solving problems.
BigInteger bign = new BigInteger (st,base); Base indicates the binary
Binary conversion
It's also a place where Java has a great advantage.
int a = Integer. parseint ("12534", 8);
System. out. println (a);
String res = Integer. toString (12345,16);
System. out. println (res);
File input and output
Only the more efficient methods are recorded here:
Write file:
Fliewriter class:
FileWriter FW = new FileWriter ("My.txt");
Fw.write ("Hello");
Fw.close ();
Read the file:
File File = new file ("My.txt");
FileInputStream FIS = new fileinputstream (file);
InputStreamReader Isreader = new inputstreamreader (FIS);
BufferedReader br = new bufferedreader (Isreader);
String SS;
while ((ss = Br.readline ()) =null) {
System. out. println (ss);
}
or directly:
File File = new file ("My.txt");
BufferedReader br =
New BufferedReader ( new InputStreamReader (new fileinputstream (file));
String SS;
while ((ss = Br.readline ()) =null) {
System. out. println (ss);
}
(I actually prefer this kind of, when writing not to be muddy)
Java one-point input and output techniques