readInt()方法的作用是读取4个输入字节,并且返回一个Int值。
假设a是读到的第一个字节,b是第二个,c是第三个,d是第四个,返回值是:
(((a & 0xff) << 24) | ((b & 0xff) << 16) |((c & 0xff) << 8) | (d & 0xff))JAVA API上的定义,你如果想读取键盘输入可以用下面的程序:
import java.io.*;
class ReadLines {
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str;
System.out.println("Enter 'exit' to quit");
do {
str = br.readLine();
System.out.println(str);
} while(!str.equals("exit"));
}
}
假设a是读到的第一个字节,b是第二个,c是第三个,d是第四个,返回值是:
(((a & 0xff) << 24) | ((b & 0xff) << 16) |((c & 0xff) << 8) | (d & 0xff))JAVA API上的定义,你如果想读取键盘输入可以用下面的程序:
import java.io.*;
class ReadLines {
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str;
System.out.println("Enter 'exit' to quit");
do {
str = br.readLine();
System.out.println(str);
} while(!str.equals("exit"));
}
}
还有我是想得到一个整数值而不是字符串,怎么样才能得到数值呢,是不是还要写一个把字符串转换成INT的函数?
str = br.readLine();
int value = Integer.parseInt(str);