import javax.swing.*;
class Wuliao
{
    public static void main(String[] args)
    {
            String input = JOptionPane.showInputDialog("please input:");
            if(input.equals("a"))  System.out.println("Hello world!");
            else if(input.equals("b"))  System.out.println("Good morning!");
            else if(input.equals("c"))  System.out.println("Good afternoon!");
            else if(input.equals("d"))  System.out.println("Good-bye!");
            else System.out.println("what?");
    }
}
 // 为什么要这个程序?puzzling...

解决方案 »

  1.   

    楼主要的是switch case把
      

  2.   

    int ch=System.in.read();
    switch(ch){
    case 'a':
        ...
        break;
    case 'b':
        ...
        break;
    }
      

  3.   

    这样的应该是你要的吧?
    import java.io.*;
    class cake {
       public static void main(String [] args) {
     
               int ch;
               try {
               while (( ch = System.in.read())!='q')  {
    switch(ch){
         case 'a':
       System.out.println("hello world");
       break;
     case 'b':
       System.out.println("Good Morning");
       break;
     case 'c':
       System.out.println("Good afternoon");
       break;
    }
               }
               System.out.println("Good bye!");
              } catch(Exception e){
                 e.printStackTrace();
              }
        }
    }
      

  4.   

    为什么那么多错误?
    baffling
      

  5.   

    import java.io.*;
    public class DoNothing{

    public static void main(String[] args){

    int ch;
               try {
               while (( ch = System.in.read())!='q')  {
    switch(ch){
    case 'a':
    System.out.println("hello world");
    break;
    case 'b':
    System.out.println("Good Morning");
    break;
    case 'c':
    System.out.println("Good afternoon");
    break;
    }
               }
               System.out.println("Good bye!");
              } catch(Exception e){
                 e.printStackTrace();
              }
    }

    }
      

  6.   

    int ch=System.in.read();
    switch(ch){
    case 'a':
        ...
        break;
    case 'b':
        ...
        break;
    }
      

  7.   

    为什么那么多错误?
    baffling
    --------
    确实有很多错误,不过那个是因为字符错误,你把所以的两个空格的都去掉就可以了
    try thisimport java.io.*;
    class cake {
     public static void main(String [] args) {
     
     int ch;
     try {
    while (( ch = System.in.read())!='q'){
    switch(ch){
    case 'a':
    System.out.println("hello world");
    break;
    case 'b':
    System.out.println("Good Morning");
    break;
    case 'c':
    System.out.println("Good afternoon");
    break;
    }
    }
     System.out.println("Good bye!");
    } catch(Exception e){
     e.printStackTrace();
    }
    }
    }
      

  8.   

    不好意思,我给错分了,baffling!怎么改过来?我问个问题,你达,我多给你分!