JAVA中有这样的语法吗:
一个字符串变量接受键盘的输入:
String input;
input=ConSole.readString();
一个字符串变量接受键盘的输入:
String input;
input=ConSole.readString();
解决方案 »
- 在UDP通信中,windows端能接收数据包但是无法发送数据包的可能原因
- 新人 请多指教
- 从java程序中启动TOMCAT
- 研究搜索引擎的高手和lucene的高手 请进 立刻给分
- 什么是Unicode Escapes!!
- 请多指教get connection from datasource fail : Cannot create JDBC driver of class '' for connect URL 'null'
- 聊天程序发送信息和接收信息问题,解决再加分
- 紧急求助,哪位有sgip1.2的协议说明文档以及java api。
- 不要编写返回引用可变对象的访问器方法--------------------要怎么理解呢
- 第一个Java程序的总结
- 如何删除D:\a下的所有文件?但要保留a文件加。他下面的文件都要删除?谢
- java类能嵌套定义吗?请大家看看这个程序
String line = br.readLine();
String str = JOptionPane.showInputDialog("put number");
System.out.println(str);
The console window is the [black] window that is automatically launched when you run a program from within CodeWarrior. Console input is any input that is entered in the console window instead of typing it into a field or dialog box that pops up in a window. For example, when the readLine method is called, the program waits for the user to enter information. Whatever the user types is returned to the program in the form of a String object.
We will use the System.in object to create an instance of the InputStreamReader class and then use that object to create an instance of the BufferedReader class.Steps for console based user input:
Use the System.in object to create an InputStreamReader object.
Use the InputStreamReader object to create a BufferedReader object.
Display a prompt to the user for the desired data.
Use the BufferedReader object to read a line of text from the user.
Do something interesting with the input received from the user.
Would you like to see some code? I thought so. Here it is:
// 1. Create an InputStreamReader using the standard input stream.
InputStreamReader isr = new InputStreamReader( System.in ); // 2. Create a BufferedReader using the InputStreamReader created.
BufferedReader stdin = new BufferedReader( isr ); // 3. Don't forget to prompt the user
System.out.print( "Type some data for the program: " ); // 4. Use the BufferedReader to read a line of text from the user.
String input = stdin.readLine(); // 5. Now, you can do anything with the input string that you need to.
// Like, output it to the user.
System.out.println( "input = " + input );
That's a lot of code for one line of input. Is there a shorter way?
Yes, most Java programmers combine steps 1 & 2 and create only one instance of the BufferedReader for use throughout their entire program. All keyboard operations will use that single shared BufferedReader object. The code below is placed with other class data members and is not inside any method.
// 1&2. Create a single shared BufferedReader for keyboard input.
private static BufferedReader stdin = new BufferedReader(
new InputStreamReader( System.in ) );import java.io.*; // needed for BufferedReader, InputStreamReader, etc. /** A Java program that demonstrates console based input and output. */
public class MyConsoleIO
{
// Create a single shared BufferedReader for keyboard input
private static BufferedReader stdin =
new BufferedReader( new InputStreamReader( System.in ) ); // Program execution starts here
public static void main ( String [] args ) throws IOException
{
// Prompt the user
System.out.print( "Type some data for the program: " );
// Read a line of text from the user.
String input = stdin.readLine(); // Display the input back to the user.
System.out.println( "input = " + input ); } // end main method } // end MyConsoleIO class
Scanner f=new Scanner(System.in)
input=System.in.read();