int dieNum = 0;
try {
    for (;;){
            System.out.print("Please input the number :");
            dieNum = System.in.read() - 48;
            System.out.println("just input die is :" + dieNum);
            if (dieNum < 0 || dieNum > 9)//判断输入的是否为数字0--9;
                 {
                   System.out.println("input again");
                   continue;//不是则从新输入;
                  } else {
                          break;//是则跳出;
                          }
            }
     } catch (IOException e) {
        e.printStackTrace();
     }

解决方案 »

  1.   

    dieNum = System.in.read() - 48;=================================System.in.read()返回的是读取的字节数:)大概思路:
    byte[] bytes
    System.in.read(bytes)
    再将bytes转化为你要数字吧
      

  2.   

    gaolch(时间就像乳沟,挤挤还是有的。) 
    你说错了,System.in.read()返回的读取到的字节,而不是字节数。
    futureroad(future)
    怎么不能预期运行,你说清楚来。
      

  3.   

    dieNum = (int)System.in.read() - 48;
      

  4.   

    eclipse3.1运行结果如下:
    Please input the number :r
    just input die is :66
    input again
    Please input the number :just input die is :-35
    input again
    Please input the number :just input die is :-38
    input again
    为什么会出现2次"input again
    Please input the number :just input die is :"
    而且还出现了两个奇怪的数字-35,-38
      

  5.   

    一点都不奇怪了,楼上都说了read读的是字节,第一次循环,读得就是第一个字节,值是114(在输入r的前提下),第二个字节是13,第三个字节应该是回车吧,值是10,所以就出现了上述情况,因为返回的是16位,所以114这个是高位字节,没有用的,13才是真正从键盘输入的数据,其它的楼主就摸索一下了
      

  6.   

    if (dieNum < '0' || dieNum > '9')判断是否位于字符'0'和'9'之间,而不是ascii码0和9之间
      

  7.   

    System.in.read() 的问题
    BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
    String readLine=in.readLine();
    int x=Integer.parseInt(readLine);
    System.out.println(x);