Read input:
To enter from the console, you first need to construct a scanner object and associate it with the standard input stream system.in.
Scanner in=new Scanner (system.in);
String Name=in.nextline (); Accept a line that may contain spaces and call the next () method if you do not want to include a space
int Age=in.nextint (); Call the Nextdouble method if you want to read a floating point number
Must be added at the beginning of the program: import java.util.*;
Formatted output:
Output the value using System.out.print (x), which prints the output x as the maximum number of non-0 digits allowed by the x corresponding data type.
The printf method in the C library function is inherited: System.out.printf ("%8.2f", X);
Input and output of the file:
To read a file, you need to construct a scanner object with the Files object:
Scanner In=new Scanner (Path.get ("MyFile.txt"));
If the file name contains a backslash, you need to add an extra backslash before the backslash: "C:\\mydirectory\\myfile.txt"
To write to a file, you need to construct a PrintWriter object. In the constructor, you only need to provide the file name:,
PrintWriter out=new printwriter ("MyFile.txt");
If the file does not exist, create the file. You can use print,println,printf like output to System.out.
Java Learning 4_ Some basic 4_ input and output _16.5.7