class Lesson22
{
public static void main(String args[])
{

char a='1';

try {
a = System.in.read();
}
catch (Exception e){}
while(a!='q')
{
System.out.println((char)a);
try {
a = System.in.read();
}
catch (Exception e){}
}
}
}
}
提示:possible loss of precisionclass Lesson22
{
public static void main(String args[])
{

int a=1;

try {
a = System.in.read();
}
catch (Exception e){}
while(a!='q')
{
System.out.println((char)a);
try {
a = System.in.read();
}
catch (Exception e){}
}
}
}
}
就是正确的,我错在那里啊

解决方案 »

  1.   

    因为System.in.read()返回的是int型的阿
    在第一个程序你直接用char 型的a来接受System.in.read()当然会出现缺失精度的问题了
    第一个程序中改成  a=(char)System.in.read()
      

  2.   

    是System.in.read()默认为int的吗?
      

  3.   

    readpublic abstract int read()throws IOExceptionReturns:
    the next byte of data, or -1 if the end of the stream is reached. ^_^,去看一下jdk文档吧 !