- Parameters for running Java programs
Java argstest Spring Java Hibernate
Args[0]--Spring
ARGS[1]--Java
ARGS[2]--Hibernate
- Get keyboard input using scanner
Scanner is a regular expression-based text scanner that resolves primitive type values and string values from File/input stream/String. The main use of the following two methods to scan the input:
-
- Hasnextxxx (): If there is a next entry, XXX can make a string of basic data types such as Int/long.
- Nextxxx (): Gets the next entry.
By default, scanner uses whitespace as a delimiter between multiple entries. You can use Usedelimiter (String pattern) to set the delimiter character. Hasnextline () and nextline () can be read row by line.
Public class scannerkeyboardtest { publicstaticvoid main (string[] args) { New Scanner (system.in); while (Sc.hasnext ()) { System.out.println ("Input:" + Sc.next ()); }}}
Public class scannerfiletest { publicstaticvoidthrows Exception { New Scanner (new File ("Scannerfiletest.java")); while (Sc.hasnextline ()) { System.out.println ("Input:" + Sc.nextline ()); }}}
- Get keyboard input using BufferedReader
ImportJava.io.BufferedReader;Importjava.io.IOException;ImportJava.io.InputStreamReader; Public classBufferedreadertest { Public Static voidMain (string[] args)throwsException {bufferedreader br=NewBufferedReader (NewInputStreamReader (system.in)); String Line=NULL; while(line = Br.readline ())! =NULL) {System.out.println ("Input:" +Line ); } }}
"Crazy Java Handout" (19)----interacting with users