How to pass parameters using the Main method
The example code is as follows:
public class MainArgs {public static void main(String[] args) {System.out.println(args.length);for(String str : args){System.out.println(str);}}}
Jvm will assign one or more strings to The args array after running the java program (one or more strings are separated by spaces. When a string contains spaces, you must enclose the complete string. Example:
Use the metric class for user input: You can enter the data type specified by the user
The separator mode is used to separate the input into tags. By default, the separator mode matches the blank. Then you can use differentNextMethod to convert the resulting tag to different types of values.
The example code is as follows:
Import java. util. imports; import java. io. file; public class ScannerKeyBoardTest {public static void main (String [] args) throws Exception {// readFileCon (); // test2 (); // enter the specified category scan = new category (System. in); Long l = scan. nextLong (); System. out. println ("l is" + l);} // returns Stringpublic static void test1 () {shortscan = new partition (System. in); // use the carriage return key as the Separator by default, and use the space tabulation key and press enter as the delimiter to pay separately. // Scan. useDelimiter ("\ n"); while (scan. hasNext () {System. out. println ("next is" + scan. next () ;}/// Longpublic static void test2 () {shortscan = new feature (System. in); // when the input is not a Long value, the loop while (scan. hasNextLong () {// blocking // System. out. println ("has over scan. nextLong () begin .... "); System. out. println ("next is" + scan. nextLong (); // System. out. println ("scan. nextLong () over has begin .... ") ;}} // read the content in the File and print it to the public static void readFileCon () throws Exception {scan = new topology (new File (" ScannerKeyBoardTest. java "); System. out. println ("fileContent is:"); while (scan. hasNextLine () {System. out. println (scan. nextLine ());}}}Read user input using the BufferedReader class: only the String class is returned.
The example code is as follows:
Import java. io. bufferedReader; import java. io. inputStreamReader; class BufferReaderKeyBoardTest {public static void main (String [] args) throws Exception {BufferedReader br = new BufferedReader (new InputStreamReader (System. in); String in = null; while (in = br. readLine ())! = Null) {System. out. println ("user input:" + in );}}}