我写了一个程序打算从键盘输入一个数然后在读入这个数到程序中,在接着输入一个数在读入,用下面方法怎么就是有问题:
System.out.println("the animal doesn't fly? In(Y/N)");
try {boolean t4_1=System.in.read( )==(int)('Y');//运行到这里CMD光标提示输入内容,从键盘输入Y ,按回车接着下面(2)
System.out.println("the animal doesn't layegg? In(Y/N)");//(2)然后屏幕输出这个,却没有光标提示从键盘输入(Y/N), 无法输入直接就运行下去了
boolean t4_2=System.in.read( )==(int)('Y');
if(t4_1&&t4_2) {
fly=true; layEgg=true;
rule4(fly,layEgg);
}
}catch(IOException e)
{ System.out.println("Error reading from user");
}
System.out.println("the animal doesn't fly? In(Y/N)");
try {boolean t4_1=System.in.read( )==(int)('Y');//运行到这里CMD光标提示输入内容,从键盘输入Y ,按回车接着下面(2)
System.out.println("the animal doesn't layegg? In(Y/N)");//(2)然后屏幕输出这个,却没有光标提示从键盘输入(Y/N), 无法输入直接就运行下去了
boolean t4_2=System.in.read( )==(int)('Y');
if(t4_1&&t4_2) {
fly=true; layEgg=true;
rule4(fly,layEgg);
}
}catch(IOException e)
{ System.out.println("Error reading from user");
}
String s = br.readLine();
用这个方法去读
import java.util.*;
public class Scan {
public static void main(String[] args) {
Scanner scann = new Scanner(System.in);
int i = scann.nextInt();
System.out.print(i);
} }