| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1443 人关注过本帖
标题:[求助]请问下面这个程序怎么了
只看楼主 加入收藏
george_vcool
Rank: 2
等 级:新手上路
威 望:3
帖 子:453
专家分:0
注 册:2007-7-23
收藏
得分:0 
一般是用!!BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
然后用: bf.readLine()//返回的是string类型!!
2007-08-18 10:56
lwj19872002
Rank: 1
等 级:新手上路
帖 子:51
专家分:0
注 册:2007-8-13
收藏
得分:0 
哦!
谢了!
我去试试!
2007-08-18 10:57
lwj19872002
Rank: 1
等 级:新手上路
帖 子:51
专家分:0
注 册:2007-8-13
收藏
得分:0 
那个循环那 怎么该啊!》
2007-08-18 11:01
lwj19872002
Rank: 1
等 级:新手上路
帖 子:51
专家分:0
注 册:2007-8-13
收藏
得分:0 
他 好象没有执行try{
buf.read(in);
}catch(IOException e){e.getStackTrace();}//

就跳过去了!!!!
2007-08-18 11:05
george_vcool
Rank: 2
等 级:新手上路
威 望:3
帖 子:453
专家分:0
注 册:2007-7-23
收藏
得分:0 

在读字符串前运行System.in.skip(2);命令就可以了!!

2007-08-18 11:52
lwj19872002
Rank: 1
等 级:新手上路
帖 子:51
专家分:0
注 册:2007-8-13
收藏
得分:0 
可是 还是有问题啊!
输入3执行后没法再执行了!
2007-08-18 13:15
george_vcool
Rank: 2
等 级:新手上路
威 望:3
帖 子:453
专家分:0
注 册:2007-7-23
收藏
得分:0 

这就得你自己检查代码了,呵呵,不要太依赖别人,自己想想原因,这样才有提高!

2007-08-18 13:29
george_vcool
Rank: 2
等 级:新手上路
威 望:3
帖 子:453
专家分:0
注 册:2007-7-23
收藏
得分:0 

我检查了一下.道理和刚才的一样,只要在我打颜色的字之后加上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));
}
}
}

2007-08-18 13:39
lwj19872002
Rank: 1
等 级:新手上路
帖 子:51
专家分:0
注 册:2007-8-13
收藏
得分:0 
  想知道为什么?
2007-08-18 13:56
lwj19872002
Rank: 1
等 级:新手上路
帖 子:51
专家分:0
注 册:2007-8-13
收藏
得分:0 
兄弟 谢了!!
程序好了!
不过还有点东西不懂!
我去查资料了!
2007-08-18 14:09
快速回复:[求助]请问下面这个程序怎么了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017121 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved