public class a {
public static void main(String[] args) {
// TODO: Add your code here
String str=null;
int s=0;
while(true)
{
System.out.println("请输入值:");
try
{
s = System.in.read();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
if (s<48 || s>58)
{
System.out.println("输入值跃界!");
System.exit(0);
}
else
{
int num=s-'0';
System.out.println(num);
}
s=0;
}
}
}
运行结果:
请输入值:
3
3
请输入值:
输入值跃界!
循环第2次时,为什么没有等我输入就出现“输入值跃界!”
public static void main(String[] args) {
// TODO: Add your code here
String str=null;
int s=0;
while(true)
{
System.out.println("请输入值:");
try
{
s = System.in.read();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
if (s<48 || s>58)
{
System.out.println("输入值跃界!");
System.exit(0);
}
else
{
int num=s-'0';
System.out.println(num);
}
s=0;
}
}
}
运行结果:
请输入值:
3
3
请输入值:
输入值跃界!
循环第2次时,为什么没有等我输入就出现“输入值跃界!”
解决方案 »
- 方法参数及返回值的问题
- 高分求 Struts 中jar包原代码!!
- jfreechart中折线图的横轴数据点太多,怎么能加一个滚条,并且设置最小间距?否则显示太模糊了。
- 请教:不返回结果,当让参数数值改变?如何实现?
- 在Java中怎样显示BMP图片?
- 求Java编码规范的详细文档,最好是象NEC那些大公司的。谢谢了!
- java中多各类时提示找不到主类
- 求一算法?谢谢!!
- TOMCAT 4.0 + IIS session 为什么会丢失 怎么才能解决?
- 使用Statement.java里的execute执行存储过程问题
- 一个用鼠标点击JTable表头可以排序指定列的Java代码
- 如何使用jacob把html转成word格式阿,加急!!!
s = System.in.read();
if (s == '\n'||s=='\r') {
continue;
}