2.6 User Enter

xiaoxiao2021-03-06  61

This part of the study is input, but it is the TIO package that is supplied with this operation. I really want to know what if I don't have to do it. This is going to study the contents of the TIO package, not the content discussed now.

// SimpleInput.java-reading numbers from the keyboardimport tio *;. // use the package tio class SimpleInput {public static void main (String [] args) {int width, height, area; System.out.println ( "type TWO Integers for " " The Width and Height of A Box "); width = console.in.readint (); height = console.in.readint (); area = width * height; system.out.print (" the Area is "); System.out.Println (Area);}}

The SimpleInput program parsing the string constant must be on one line and cannot be typed between the quotation marks. If the string to be printed is too long, it cannot be displayed in one line, it can be divided into a few segments, then connect them with the connection " ". "Cannot display in one line" refer to the development environment "I don't want to be in one line" (for example, too long will be exceeding the right boundary to read difficult), if you want to divide two lines in two lines when the program is running, To write two sentences "System.out.Println ()". Console.in.readint (), console is a "class" in the TIO "package", which is a "subclass" in Console, and last readint () is a "method" in in in. This is me. Understanding. As for final, the book is written "to ensure that the last line of printing statements have ln. No, no output will be displayed on the screen." Here is the last line of printing the statement to "system.out.print ()" The result of the "command prompt" mode in the XP attachment, the output is still there, but there is only one blank line. However, in order to ensure the consistency of the program, I still comply with the statement in the book (last line plus LN). Two console.in.readint () in the program, two numbers can be written in one line, with blank (blank including spaces, TAB tabs, and auto-return ends), or write One line (that is, using the Enterprise).

E: / Program Files / j2sdk1.4.2 / Java Application> javac SimpleInput.java E: / Program Files / j2sdk1.4.2 / Java Application> java SimpleInputtype two integers for the width and height of a box10 50The area is 500E: / Program Files /J2SDK1.4.2/Java Application>

转载请注明原文地址:https://www.9cbs.com/read-84888.html

New Post(0)