一段简单的java 代码 解释

来源:百度知道 编辑:UC知道 时间:2024/05/27 01:32:47
while (!done)
{
System.out.println("Input an entry:");
next = keyboard.nextLine( );
toDoList.addElement(next);
System.out.print("More items for the list? ");

ans = keyboard.next( );
keyboard.nextLine( ));//在这里什么意思
if (!(ans.equalsIgnoreCase("yes")))
done = true;
}
keyboard.nextLine( )); 要是没有这句话 再输入yes后回车 循环条件成立为什么还是没法继续输入 ,每次都跳到
System.out.print("More items for the list? ");

ans = keyboard.next( ); 这里来

import java.util.*;
import java.io.*;

public class VectorDemo{

public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));//new

Vector<String> toDoList = new Vector<String>(10);
System.out.println( "Enter items for the list, when prompted.");
boolean done = false;
String next = null;
String ans=null;
//Scanner keyboard = new Scanner(System.in);
while (!done) {
System.out.println("Input an entry:");
//next = keyboard.nextLine( );
try {
next= br.readLine();
} catch (Exception e) {
e.printStackTrace();
}
toDoList.addElement(next);
System.out.print("More items for the list:");
//ans = keyboard.next( );
//keyboard.next( );
try {
ans=br.readLine();
} catch (Exception e2) {
e2.printS