Input and output of Java SE entry

Source: Internet
Author: User
Tags java se

In the first, eight basic types of time, I introduced the output, of course, these outputs are simple, subsequent writes to the stream when the input output is refined.

It is now only required to understand the input and output. The input is actually accepting the keyboard input.

 Public class Hello {     publicstaticvoid  main (string[] args) {          int  a=;          System.  out . println (a);    }}

20 in the appeal code, can I enter it through the console??? The answer is yes, what are the criteria for the input???

1 Import java.util.Scanner jar package, import keyword called import

2. In the program weight input Scanner input =new Scanner (system.in);, where new is an object, and System.in is an enumeration, these follow-up writes object-oriented time will say, temporarily as long as you know how to write it.

Let's take a look at how to accept keyboard input.

corresponding Code

import Java.util.Scanner; Public classHello { Public Static voidMain (string[] args) {Scanner input=NewScanner (System.inch); DoubleD=input.nextdouble (); System. out. println ("The Double value you entered ="+d); intI=Input.nextint (); System. out. println ("the int value you entered ="+i); String s=Input.next (); System. out. println ("The string value you entered ="+s); }}

Only three types are listed, other types are equivalent. We can accept any value entered by the keyboard.

We let the keyboard enter a square edge to find the circumference and area of the square.

Write a keyboard input circle radius to find the circumference and area of the circle.

import Java.util.Scanner; Public classHello { Public Static voidMain (string[] args) {Scanner input=NewScanner (System.inch); System. out. println ("Please enter the side length of the square and press ENTER when finished"); DoubleD=input.nextdouble (); DoubleZhouchang =d*4;//         Doublemianji=d*D; System. out. println ("the circumference of a square ="+zhouchang+"area ="+Mianji); System. out. println ("I heard that you also require the circumference and area of the circle, clear the radius of the direct input Circle"); DoubleR=input.nextdouble (); DoublePi=3.14; Zhouchang=2*pi*R; Mianji=pi*r*R; System. out. println ("circumference of the circle ="+zhouchang+"area ="+Mianji); }}

Input and output of Java SE entry

Related Article

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.