获取并判断手动输入的信息
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退出系统!");
}
}
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退出系统!");
}
}