请各位高手解决一个问题???急待!!请看下面的代码!

dzeng81 2004-10-04 02:15:12
import java.io.*;
public class InOut
{
public static void main(String args[])
{
char c;
System.out.print("enter a character please:");
try{
c=(char)System.in.read();
}catch(IOException e){};
System.out.println("you'v entered charactor "+c);
}
}


//编译始终通不过,报错如下:
--------------------Configuration: j2sdk1.4.2 <Default>--------------------
D:\java\Java Code\InOut.java:11: variable c might not have been initialized
System.out.println("you'v entered charactor "+c);
^
1 error


...全文
63 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
skylan 2004-10-12
  • 打赏
  • 举报
回复
public class InOut{
public static void main(String[] args)
{
System.out.print("enter a character please:");
try{char c;
c=(char)System.in.read();
}catch(Exception e){}
System.out.println("you'v entered charactor "+ "c");
}
}
局部变量包含到try catch块中,并且catch后面的{}不加分号
skylan 2004-10-12
  • 打赏
  • 举报
回复
public class InOut
{
public static void main(String[] args)
{
System.out.print("enter a character please:");
try{char c;
c=(char)System.in.read();
}catch(Exception e){}
System.out.println("you'v entered charactor "+ "c");
}
局部变量包含到try catch块中,并且catch后面的{}不加分号。
}
jhyan 2004-10-04
  • 打赏
  • 举报
回复
局部变量要明确先初始化,例如c='a';
dzeng81 2004-10-04
  • 打赏
  • 举报
回复
我开始以为是版本不同的缘故,但我用各个版本进行了调试,同样出现了这个问题!请问这是什么原因咯!

50,530

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧