"Crazy Java Handout" (19)----interacting with users

Source: Internet
Author: User

    • 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:

      1. Hasnextxxx (): If there is a next entry, XXX can make a string of basic data types such as Int/long.
      2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.