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...
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...
switch(ch){
case 'a':
...
break;
case 'b':
...
break;
}
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();
}
}
}
baffling
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();
}
}
}
switch(ch){
case 'a':
...
break;
case 'b':
...
break;
}
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();
}
}
}