我在控制台下写了如下代码:
System.out.println("输入数字:");
int s = System.in.read();
System.out.println("输出数字:"+ s);
但是有问题,我输入1,输出的是49;
我输入100,输出的也是49;
有没有什么方法使我输入什么数字,我读取的就是什么数字??
System.out.println("输入数字:");
int s = System.in.read();
System.out.println("输出数字:"+ s);
但是有问题,我输入1,输出的是49;
我输入100,输出的也是49;
有没有什么方法使我输入什么数字,我读取的就是什么数字??
public class TestString {
public static void main(String args[]) {
InputStreamReader isr =
new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String s = null;
try {
s = br.readLine();
while(s!=null){
if(s.equalsIgnoreCase("exit")) break;
System.out.println(s);
s = br.readLine();
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}