import java.io.IOException;public class Lifan {
public static void main(String[] args) throws IOException {
int x = System.in.read();
while (x != 9) 
{
if(x==4)
break;
else
{
 System.out.println("OK1");
 break;
}
}
int y = 3;
do 
{
System.out.println("OK2");
y++;
} while (y == 0);
for (int z = 1; z < 10; z++) 
{
System.out.println("z=" + z);
} }
}以上的是代码部分 
使用在键盘上输入字符  当你输入4的时候  OK1为什么还是在屏幕上输出了  帮忙解释下

解决方案 »

  1.   

    int x = System.in.read(); 你输入4 的时候,这里的X是 52,所以出问题。
      

  2.   

    system.in.read()方法的作用是从键盘读出一个字符,然后返回它的Unicode码。
      

  3.   

    BufferedReader in
        = new BufferedReader(new InputStreamReader(System.in));
        String f = in.readLine();
          int x = Integer.parseInt(f); 
          while (x != 9) 
          { 
          if(x==4) 
          break; 
          else 
          { 
          System.out.println("OK1"); 
          break; 
          } 
          } 
          int y = 3; 
          do 
          { 
          System.out.println("OK2"); 
          y++; 
          } while (y == 0); 
          for (int z = 1; z < 10; z++) 
          { 
          System.out.println("z=" + z); 
          } 
      

  4.   

    从键盘读取:
    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); 
    Stirng str = stdin.readLine();
    然后你操作str就可以了
      

  5.   

    int y = 3; 
    do 

    System.out.println("OK2"); 
    y++; 
    } while (y == 0); 你这是在做什么?相当于一个死循环
      

  6.   

    4的Unicode码是52!定义int并不是输入4   x就是4!而是Unicode码的整数码52!其实你输入的任何东西都属于字符串!不管是4还是abc!都属于字符串类型!你可以这样    
       String x= System.in.read();   后面的If(x.equals("4"))这样应该可以了!