来编这个程序,简单的switch

zhaozai2003 2004-09-10 04:37:40
编写程序要求用户输入一个字符,当用户输入a的时候,程序响应“Hello world!”,当用户输入b的时候程序响应“Good morning!”,当用户输入c的时候程序响应“Good afternoon!”,当用户输入q的时候程序输出“Good-bye!”并结束用户输入其它字符的时候程序响应“what?”

请写出程序.
...全文
223 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhaozai2003 2004-09-14
  • 打赏
  • 举报
回复
不好意思,我给错分了,baffling!怎么改过来?我问个问题,你达,我多给你分!
zhaozai2003 2004-09-14
  • 打赏
  • 举报
回复
ok,baffling,给分!
haroyy 2004-09-13
  • 打赏
  • 举报
回复
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();
}
}

}
baffling 2004-09-13
  • 打赏
  • 举报
回复
有什么错误?我运行过的,是好的啊!
zhaozai2003 2004-09-13
  • 打赏
  • 举报
回复
为什么那么多错误?
baffling
tdmlxq 2004-09-13
  • 打赏
  • 举报
回复
大家都写了,那我就不写了
redlaputa 2004-09-13
  • 打赏
  • 举报
回复
为什么那么多错误?
baffling
--------
确实有很多错误,不过那个是因为字符错误,你把所以的两个空格的都去掉就可以了
try this

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();
}
}
}
wandou999 2004-09-13
  • 打赏
  • 举报
回复
int ch=System.in.read();
switch(ch){
case 'a':
...
break;
case 'b':
...
break;
}
baffling 2004-09-10
  • 打赏
  • 举报
回复
这样的应该是你要的吧?
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();
}
}
}
treeroot 2004-09-10
  • 打赏
  • 举报
回复
int ch=System.in.read();
switch(ch){
case 'a':
...
break;
case 'b':
...
break;
}
mashimaro24 2004-09-10
  • 打赏
  • 举报
回复
楼主要的是switch case把
32zyc 2004-09-10
  • 打赏
  • 举报
回复
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...

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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