一段简单的java 代码 解释
发布网友
发布时间:2022-05-04 22:32
我来回答
共1个回答
热心网友
时间:2022-06-26 15:00
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.printStackTrace();
}
if (!ans.equalsIgnoreCase("yes")){
done = true;
}
}//end of whlie
System.out.println("The list contains:");
int position;
int vectorSize = toDoList.size( );
for(position = 0; position < vectorSize; position++){
System.out.println(toDoList.elementAt(position));
}
}//end of public static void main
}