package Test;
import java.util.Scanner;
public class Test1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入您的座位类型: ");
String ty = sc.next();
System.out.println("请输入你的航班月份(1-12): ");
int mon = sc.nextInt();
System.out.println("请输入你的机票价格: ");
double pri = sc.nextDouble();
System.out.println(calcu(ty,mon,pri));
}
public static double calcu(String type,int month,double price){
if (type == "经济舱"){
if(month >= 5 && month <= 10){
price *= 0.85;
}
else if (month == 12 ||month == 11 || month >=1 && month <= 4){
price *= 0.65;
}
else {
System.out.println("无效月份");
price = -1;
}
}
else if (type == "头等舱"){
if(month >= 5 && month <= 10){
price *= 0.9;
}
else if (month == 12 ||month == 11 || month >=1 && month <= 4){
price *= 0.7;
}
else {
System.out.println("无效月份");
price = -1;
}
}
else{
System.out.println("无效");
price = -1;
}
return price;
}
}
有大佬知道为什么我的ty不能进入type里匹配吗,一直运行else分支,就算我输入的是头等舱或者经济舱,也不会进入if 和else if线