改改:char c=' '; //给个初值

解决方案 »

  1.   

    "c" not 初期化,
    following is ok.import java.io.*;
    class simpleio 
    {
    public static void main(String[] args) 
    {
    char c;
    c = ' ';
    System.out.println("enter a letter:");
    try{
    c=(char)System.in.read();
    }
    catch(IOException e){};
    System.out.println("the letter is :"+c);
    }
    }
      

  2.   

    c没有初始化。
    c=(char)System.in.read();因为这一句有可能有异常,所以报错。
      

  3.   

    不要再捕获异常后不对异常进行任何处理,这样容易出错。
    import java.io.*;
    class simpleio 
    {
    public static void main(String[] args) throw IOException
    {
    char c;
    System.out.println("enter a letter:");
    try{
    c=(char)System.in.read();
    }
    catch(IOException e){
                          throw e;
                      };
    System.out.println("the letter is :"+c);
    }
    }
      

  4.   

    错了,是throws
    import java.io.*;
    class simpleio 
    {
    public static void main(String[] args) throws IOException
    {
    char c;
    System.out.println("enter a letter:");
    try{
    c=(char)System.in.read();
    }
    catch(IOException e){
                          throw e;
                      };
    System.out.println("the letter is :"+c);
    }
    }
      

  5.   

    import java.io.*;
    class simpleio 
    {
    public static void main(String[] args) throw IOException
    {
    char  c = null;
    System.out.println("enter a letter:");
    try{
    c=(char)System.in.read();
    }
    catch(IOException e){
                          throw e;
                      };
    System.out.println("the letter is :"+c);
    }
    }
      

  6.   

    楼上说的是对的!也可以这么做!
    import java.io.*;
    class simpleio 
    {
    public static void main(String[] args) 
    {
    char c;
                    
    System.out.println("enter a letter:");
    try{
    c=(char)System.in.read();
                            System.out.println("the letter is :"+c);
    }
    catch(IOException e){};

    }
    }
    其实char是可以不初始化的!但你在打印输出之前得做!
    你把System.out.println("the letter is :"+c);提到和赋值在一个模块里!就可以编译通过拉!
      

  7.   

    给你个更好得代码!
    是用字符流类处理得!
    import java.io.*;class BRRead{
      
      public static void main(String arg[])    throws IOException   {
     
         char c;
     
         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
             System.out.println("Enter characters,'q' to quit.");    //read characters
     
         do{
     
            c=(char)br.read();
     
          System.out.println(c) ;
      
        }while(c!='q');   } }
      

  8.   

    用JAVA的时候一定要注意
    一定要在构造函数中付出值,否则不能进行任何操作
    这点和C可是大大的不一样呀这个错误我也犯了好几次了
    不过现在不会了