Five ways to type in Java----

Source: Internet
Author: User

  Packagecom.test.Log4j; ImportJava.io.BufferedReader; ImportJava.io.Console; Importjava.io.IOException; ImportJava.io.InputStreamReader; ImportJava.util.Scanner; ImportJavax.swing.JOptionPane; Importjunit.framework.TestCase;  Public classInputtestextendsTestCase {/*** Using byte input classes*/        Public voidTestbytereader () {String s= ""; System.out.println ("Bytereader Mode Input"); byte[] Readin =New byte[50]; intCount = 0; Try{System.out.println ("You input:"); Count=System.in.read (Readin); }Catch(Exception e) {e.printstacktrace (); } System.out.println (NewString (Readin, 0, Count)); }              /*** using character input stream*/        Public voidTestbufferedreader () {String s= ""; BufferedReader BR=NewBufferedReader (NewInputStreamReader (system.in)); System.out.println ("Bufferreader Mode Input"); Try{s=Br.readline (); } Catch(IOException e) {e.printstacktrace ();                             } System.out.println (s); }    /*** Scanner Class (Scanner) Read string from console*/        Public voidTestscanner () {String s= ""; Scanner SC=NewScanner (system.in); System.out.println ("Scanner Mode input"); S=Sc.next ();              System.out.println (s); }       /*** dialog box input data*/        Public voidTestjoptionpane () {System.out.println ("Joptionpane Mode Input"); String name= Joptionpane.showinputdialog ("What is your name?"));              SYSTEM.OUT.PRINTLN (name); }        Public voidTestConsole () {/**jdk1.6 New Features * Java to interact with the console, it is not always possible to get the Java * Console class available. Whether a JVM has an available console depends on how the underlying platform and JVM are called *.           If the JVM was started in an interactive command line (such as Windows CMD *) and the input output is not redirected to another location, then we can get an available console instance.           * When you run the above code in eclipse or Netbean, the following text output will be available in the console: console is unavailable.           * * indicates that the Java program could not get the console instance because the JVM was not invoked on the command line, or the input output was redirected. */Console Console=System.Console (); if(Console = =NULL) {                      Throw NewIllegalStateException ("Cannot use console"); } String S= Console.ReadLine ("Enter your parameters");              System.out.println (s); }               Public Static voidMain (string[] args) {/*** Main function parameter input*/System.out.println (args[0]); }          }

Five ways to type in Java----

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.