Java SE entry-level input and output, javase

Source: Internet
Author: User
Tags java se

Java SE entry-level input and output, javase

 

In the first article, I introduced the output for the eight basic types. Of course, these outputs are simple. When writing to the stream, I will refine the input and output.

Now, you only need to understand the input and output. The input is actually the input of the keyboard.

 

public class Hello {     public static void main(String[] args ) {          int  a=20;          System.out.println(a);    }}

In the appeal Code 20, can I enter it through the console ??? The answer is yes. What are the conditions for the input ???

1. Import the jar package of java. util. keystore. The imported keyword isImport

2. input weight input = new weight (System. in);, where new is an object of the new instance, System. in is enumeration, which will be described later when writing Object-oriented Data. You only need to know this for the time being.

Let's take a look at how keyboard input is accepted.

Corresponding code

Import java. util. extends; public class Hello {public static void main (String [] args) {extends input = new loads (System. in); double d = input. nextDouble (); System. out. println ("the double value you entered =" + d); int I = 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 the same. We can accept any value input by the keyboard.

Let's enter the side of a square on the keyboard to find the circumference and area of the square.

Enter the circle radius on the keyboard to obtain the circumference and area of the circle.

 

Import java. util. extends; public class Hello {public static void main (String [] args) {extends input = new loads (System. in); System. out. println ("Enter the side length of the square. Press Enter after the input is complete"); double d = input. nextDouble (); double zhouchang = d * 4; // double mianji = d * d; System. out. println ("square perimeter =" + zhouchang + "Area =" + mianji); System. out. println ("I heard that you also require the circumference and area of the circle, clear and directly enter the radius of the circle"); double r = input. nextDouble (); double Pi = 3.14; zhouchang = 2 * Pi * r; mianji = Pi * r; System. out. println ("circle perimeter =" + zhouchang + "Area =" + mianji );}}

 

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.