Java Small Example

Source: Internet
Author: User

Want to learn BASIC time, get user input how simple, on an input; later, C, also quite simple, a scanf (); later, C + +, as simple as a cin <<; to Java here, trouble.

1, simple access to user input

The following is a basic example that contains an explanation:

1.import Java.io.BufferedReader;
2.import Java.io.InputStreamReader;
3.import java.io.IOException;
4.
5.public class Basicinput {
6.
7. Public    static void Main (string[] args) {
8.        try {
9.            In Java, user input is obtained by InputStream (input stream)

.
Ten.            System.in is the input stream of the system. By default, this input stream is connected

to the console (the command line). One by one
.            InputStreamReader is the class used to read InputStream. A
.            InputStreamReader is_reader = new InputStreamReader

(system.in);            
-April.            BufferedReader is typically used to read character

string content in InputStream.
.            BufferedReader can read one row at a time.
.            String str = new BufferedReader (is_reader). ReadLine ();
.            Prints the read string to the screen.
.            SYSTEM.OUT.PRINTLN ("You entered is:" + str);        catch (IOException e) {
.            E.printstacktrace ();
.    }
24.}

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.