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为什么还是在屏幕上输出了 帮忙解释下
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为什么还是在屏幕上输出了 帮忙解释下
= 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);
}
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
Stirng str = stdin.readLine();
然后你操作str就可以了
do
{
System.out.println("OK2");
y++;
} while (y == 0); 你这是在做什么?相当于一个死循环
String x= System.in.read(); 后面的If(x.equals("4"))这样应该可以了!