Java控制台程序典型范例----天气系统

                                         获取并判断手动输入的信息

                   import java.util.*;
public class Weather{


public static void main(String[] args) {
Weather   translator = new Weather();
translator.start();
}


public String translation(String c){
String weather = "";
if(c.equals("D")){
weather = "干燥";
}else if(c.equals("M")){
weather = "阴天";
}else if(c.equals("H")){
weather = "天晴";
}else if(c.equals("R")){
weather = "下雨";
}
return weather;
}

public void start(){
String con = "y";
Scanner input = new Scanner(System.in);
String c = "";
String weather = "";
System.out.println("*****欢迎使用天气识别器*****");
while(con.equals("y")){
System.out.print("\n请输入天气状况的第一个英文字母:");
c = input.next();
weather = translation(c.toUpperCase());
if(!weather.equals("")){
   System.out.println(weather);
}else{
System.out.println("输入错误,无法判断!");
}
System.out.print("\n您想再试一遍吗? (y/n)");
con = input.next();
}
System.out.println("\n退出系统!");
}


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值