import java.io.*; 
public class aaa { public static void main(String[] args) { 
BufferedReader in = new BufferedReader( 
            new InputStreamReader(System.in)); 
String[] arr = new String[3]; 
try{ 
for(int i = 0;i < arr.length;i++)  
{  
System.out.println("输入:");  
String x = in.readLine();  
arr[i] = x;  System.out.println("是否继续?(Y/N)");  
char c = (char)in.read();  if(c == 'Y')  
{  
continue;  
}  
else if(c == 'N')  
{  
break;  
}  
}  

catch(IOException e){} 
catch(NumberFormatException e){} 


我想每次“输入”之后选择Y的时候都继续“输入”,第一次输入是正常的,可是选择Y之后第二次“输入”却不执行,直接询问是否继续,“String x = in.readLine();”这句在第二次输入的时候不起作用,这是为什么啊?

解决方案 »

  1.   

    import java.io.*; 
    public class aaa { public static void main(String[] args) { String[] arr = new String[3]; 
    try{ 
    for(int i = 0;i < arr.length;i++)  
    {  BufferedReader in = new BufferedReader( 
                new InputStreamReader(System.in)); 
    System.out.println("输入:");  
    String x = in.readLine();  
    arr[i] = x;  System.out.println("是否继续?(Y/N)");  
    char c = (char)in.read();  if(c == 'Y')  
    {  
    continue;  
    }  
    else if(c == 'N')  
    {  
    break;  
    }  
    }  

    catch(IOException e){} 
    catch(NumberFormatException e){} 

    }
      

  2.   

    真的可以,谢谢楼上,可为什么只把BufferedReader放在循环里就解决了?这是什么原因?
      

  3.   

    用一次就没了 
    要重新申请对象把  
    习惯是这样的拉  哇哈哈  
    最好还加句in.close();