| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1443 人关注过本帖
标题:[求助]请问下面这个程序怎么了
只看楼主 加入收藏
lwj19872002
Rank: 1
等 级:新手上路
帖 子:51
专家分:0
注 册:2007-8-13
收藏
 问题点数:0 回复次数:21 
[求助]请问下面这个程序怎么了

import java.io.*;
public class testinput {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int in=0;
try{
in=System.in.read();
}catch(IOException e){e.getStackTrace();}
System.out.println(in);

}

}
编译能过!运行有问题!!

搜索更多相关主题的帖子: void public import method 
2007-08-17 23:45
george_vcool
Rank: 2
等 级:新手上路
威 望:3
帖 子:453
专家分:0
注 册:2007-7-23
收藏
得分:0 
我测试了一下,没有问题!!
注意in是返回的字符的ascii码值!!
如果输入1,输出为49
2007-08-17 23:59
J华
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2007-7-2
收藏
得分:0 
一看你就学过C..

Java貌似是Unicode编码..
2007-08-18 00:20
george_vcool
Rank: 2
等 级:新手上路
威 望:3
帖 子:453
专家分:0
注 册:2007-7-23
收藏
得分:0 
呵呵,谢谢三楼改正!!!
2007-08-18 01:55
lwj19872002
Rank: 1
等 级:新手上路
帖 子:51
专家分:0
注 册:2007-8-13
收藏
得分:0 

可是我在我机子上面运行了有错啊!!!!
高手看看啊!!

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

我也运行了一下,没有错误?
你的错误是什么??
贴出来或许会有人能帮你!

2007-08-18 09:24
lwj19872002
Rank: 1
等 级:新手上路
帖 子:51
专家分:0
注 册:2007-8-13
收藏
得分:0 

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 09:29
lwj19872002
Rank: 1
等 级:新手上路
帖 子:51
专家分:0
注 册:2007-8-13
收藏
得分:0 

原程序是这有样的1

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

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)//这个循环一次完后要将j置为一个不是123的数!!
{
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();}//这段代码输入的与写在in里面的不一样.这样用流不合适!!!
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 10:33
lwj19872002
Rank: 1
等 级:新手上路
帖 子:51
专家分:0
注 册:2007-8-13
收藏
得分:0 

那要 输入 怎么用》?

2007-08-18 10:36
快速回复:[求助]请问下面这个程序怎么了
数据加载中...
 
   



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

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