import java.io.*; //需要的class java_in{
static int i;
public static void main(String args[]){
try
{
i=System.in.read();
System.out.println("I="+i); // <<---这句报不会出错了
}
catch(IOException e) //catch 在io中很重要的
{}
}
}
static int i;
public static void main(String args[]){
try
{
i=System.in.read();
System.out.println("I="+i); // <<---这句报不会出错了
}
catch(IOException e) //catch 在io中很重要的
{}
}
}
应该是:
public class java_in
a.i = system.in.read();试试看。
我照你说的重写了遍现是不报错了,可输入和输出的数字不一样呀.输入0他给我输出40几.何解?谢谢
System.out.println("I="+i);
改成
System.out.println("I="+(char)i);
boolean ok=false;
String str="";
int n;
try
{
while(!ok)
{
n=System.in.read();
if(n<0||(char)n=='/n')
ok=true;
else
str+=(char)n;
}catch(IOException)
{
ok=true;
}
}
{
try
{
n=System.in.read();
if(n<0||(char)n=='/n')
ok=true;
else
str+=(char)n;
}catch(IOException)
{
ok=true;
}
}
修改程序如下:(可满足楼主的要求) bafce(bafce)
painAndhappy((痛并快乐着))
两位兄弟的建议不错,有收获import java.io.*; class java_in{
static int i;
public static void main(String args[]){
boolean ok=false;
String str="";
while(!ok)
{
try
{
i=System.in.read();
if((char)i=='\n')
ok=true;
else
str+=(char)i;
}
catch(IOException e)
{
ok=true;
}
}
System.out.println("I="+str);
}
}
读入的是int类型的,对应的是ASCII表,查查每本程序设计的书后面都有的
楼主不信可以把我一楼的程序运行,对应着ASCII表看看
只能读到一个字符(如果输入多个其它的作废),而且返回的是相应的acsii
值。
有什么作用?