然后用: bf.readLine()//返回的是string类型!!
在读字符串前运行System.in.skip(2);命令就可以了!!
这就得你自己检查代码了,呵呵,不要太依赖别人,自己想想原因,这样才有提高!
我检查了一下.道理和刚才的一样,只要在我打颜色的字之后加上System.in.skip(2);
package test_01;
import java.util.*;
import java.io.*;
class testver
{
public static void main(String[] args)
{
Vector<String> ver=new Vector<String>(5,1);
ver.add(0," lwj");
ver.add(1, "lwk");
ver.add(2, "lwl");
ver.add(3, "lwh");
ver.add(4, "lwu");
int count=ver.size();
System.out.println("This is a vector!\nThere are "+count+"members:");
System.out.println("NO. Element");
for(int i=0;i<count;i++)
{
System.out.println(" "+i+" "+ver.get(i));
}
System.out.println("You can input <1> or <2> to choose:");
System.out.println("<1>:Add a new element!");
System.out.println("<2>:Delet a element!\n<3>:To viewer all of them!");
System.out.println("<4>:To exit!");
System.out.println("Please choose:");
int j=0;
try {j=System.in.read()-'0';}catch(IOException e){e.getStackTrace();}
while(j==1||j==2||j==3)
{
switch(j)
{
case 1:add(ver);break;
case 2:delet(ver);break;
case 3:vew(ver);break;
}
System.out.println("Please choose again!");
try {j=System.in.read()-'0';}catch(IOException e){e.getStackTrace();}
}
}
public static void add(Vector<String> ver)
{
DataInputStream din=new DataInputStream(System.in);
BufferedInputStream buf=new BufferedInputStream(din);
System.out.println("Please input what you want to add:");
String str;
byte[] in=new byte[100];
try{
buf.read(in);
}catch(IOException e){e.getStackTrace();}
str=in.toString();
ver.addElement(str);
System.out.println("Successed!");
try{
din.close();
buf.close();
}catch(IOException e){e.getStackTrace();}
}
public static void delet(Vector<String> ver)
{
System.out.println("Please input the index of the element you want to delet!");
int index=0;
try{
index=System.in.read();
ver.remove(index);
}catch(IOException e){e.getStackTrace();}
System.out.println("Successed!!");
}
public static void vew(Vector<String> ver)
{
System.out.println("The all elements are:");
System.out.println("NO. Element");
for(int i=0;i<ver.size();i++)
{
System.out.println(" "+ i+" "+ver.get(i));
}
}
}