System.in.read 读取的是单个字符,返回的就是一个 int 型,不需要做转换,这个 int 值就是它读的那个字符的 ASCII 码。关于读取的问题,这里有一个小小的示例,看看吧/** * @(#) Test.java * @author fancy */import java.io.*;public class Test { public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int a = Integer.parseInt(reader.readLine()); int b = Integer.parseInt(reader.readLine()); System.out.println("a = " + a + ", b = " + b); }}
public static void read(){ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String str=""; String string[] = new String[100]; int i = 0; try{
* @(#) Test.java
* @author fancy
*/import java.io.*;public class Test { public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int a = Integer.parseInt(reader.readLine());
int b = Integer.parseInt(reader.readLine());
System.out.println("a = " + a + ", b = " + b);
}}
ASCII值
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str="";
String string[] = new String[100];
int i = 0;
try{
while((str = br.readLine()).equals("q") != true){
System.out.println("\t" + str);
string[i] = str;
i = i + 1;
}
}catch(Exception e){
System.out.println(e.toString());
}
for(int j=0;j<i;j++)System.out.println(string[j]);
}