public class Argstest{public static void Main (string[] args) {System.out.println (args.length), for (int i=0;i< args.length;i++) {System.out.println (args[i]);}}
Javac Argstest.java Compile the program.
Executes the Java argstest Run program.
In addition, you can use scanner to get input from the keyboard in Java.
Import Java.util.scanner;public class Scannertest{public static void Main (string[] args) {Scanner sc= new Scanner ( system.in); while (Sc.hasnext ()) {System.out.println ("keyboard input content is:" +sc.next ());}}}
Operation Result:
Of course scanner not only can read the input of the keyboard, but also can read the input of the file.
Import Java.io.file;import Java.io.ioexception;import Java.util.scanner;public class Scannerfiletest{public static void Main (string[] args) {Scanner sc=null;try{sc=new Scanner (New File ("Scannerfiletest.java"));} catch (IOException e) {System.out.println ("IOException");} System.out.println ("Scannerfiletest content:"); while (Sc.hasnextline ()) {System.out.println (Sc.nextline ());}}}
Operation Result:
Java program Main method parameter string[] args