它是要求你必须catch IOException或者在你的main方法的声明上加上throws IOException

解决方案 »

  1.   

    什么书?这么烂,类名小写,不算,case '2';下面还多了一个break,换一本学吧,呵呵
      

  2.   

    强烈建议换书有那么多好东东的JAVA书,为什么你会选取中这一本,也是你的造化呀!散点分给我吧。
      

  3.   

    package break1;import java.io.*;class switchtest
    {
    public static void main(String test[]) throws IOException
    {
    char a;
    System.out.println("choose a number 1-3:");
    a=(char)System.in.read();
    switch(a)
    {

                case '0':
    System.out.println("\n You have entered a 0.");   
    break; 
    case '1':
    System.out.println("\n You have entered a 1.");
    case '2':
    break;
    System.out.println("\n You have entered a 2.");
    break;
    case '3':
    System.out.println("\n You have entered a 3.");
    break;
    default:
    System.out.println("\n you have entered a wrong number!");
    }
    }
    }
      

  4.   

    package break1;
    import java.io.*;
    class switchtest
    {
    public static void main(String test[])
    {
    char a;
    System.out.println("choose a number 1-3:");
               try{
    a=(char)System.in.read();
    switch(a)
    {

                case '0':
    System.out.println("\n You have entered a 0.");   
    break; 
    case '1':
    System.out.println("\n You have entered a 1.");
    case '2':
    break;
    System.out.println("\n You have entered a 2.");
    break;
    case '3':
    System.out.println("\n You have entered a 3.");
    break;
    default:
    System.out.println("\n you have entered a wrong number!");
    }
                 }catch(IOException e){
                    System.err.println(e);
                 }
    }
    }
      

  5.   

    jimshen(jimshen)
    非常感谢你,不过编译有以下提示,是为什么?--------------------Configuration: test - j2sdk1.4.0 <Default>--------------------
    d:\Program Files\Xinox Software\JCreator Pro\MyProjects\breaks\test\case2.java:22: unreachable statement
    System.out.println("\n You have entered a 2.");
                            ^
    1 errorProcess completed.
      

  6.   

    package break1;
    import java.io.*;
    class switchtest
    {
    public static void main(String test[])
    {
    char a;
    System.out.println("choose a number 1-3:");
               try{
    a=(char)System.in.read();
    switch(a)
    {

                case '0':
    System.out.println("\n You have entered a 0.");   
    break; 
    case '1':
    System.out.println("\n You have entered a 1.");
    case '2':
    // break;//多写了一行而已
    System.out.println("\n You have entered a 2.");
    break;
    case '3':
    System.out.println("\n You have entered a 3.");
    break;
    default:
    System.out.println("\n you have entered a wrong number!");
    }
                 }catch(IOException e){
                    System.err.println(e);
                 }
    }
    }