相关参考:http://www.diyjava.com/jcrm/ShowArticle.asp?ArticleID=2538
1、输入 获取字符串
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class ReadString
{
public ReadString()
{
}
public static void main(String [] arguments)throws Exception
{
System.out.println("请输入内容");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String inputStr = br.readLine();
System.out.println(inputStr);
}
}
2、输入字符 或者整数
直接使用System.in.read()方法返回得是int型得值,需要转换
import java.io.*;
public class Input1
{
public static void main(String args[]) throws IOException
{
System.out.println("Input: ");
byte buffer[] = new byte[512]; //输入缓冲区
int count = System.in.read(buffer); //读取标准输入流
System.out.println("Output: ");
for (int i=0;i<COUNT;I++) 输出buffer元素值
{
System.out.print(" "+buffer[i]);
}
System.out.println();
for (int i=0;i<COUNT;I++) 按字符方式输出buffer
{
System.out.print((char) buffer[i]);
}
System.out.println("count = "+ count); //buffer实际长度
}
}
输出
System.print.out();
System.println.out();
本文比较基础,供自己以后学习参考用