-3
我的代碼不會輸出switch語句我需要使用不同的語句還是條件?直到switch語句的每一件事情都完美無缺。開關狀態不輸出;幫幫我;
import java.util.Scanner;
public class NewClass {
public static void main (String[]args){
Scanner user= new Scanner(System.in);
int hours;
double biWeekly,payrate,weekly;
String payPeriod;
//Variables
System.out.print("Do you get paid weekly or bi weekly?:");
payPeriod=user.nextLine();
System.out.print("How many hours did you work ths week?:");
hours=user.nextInt();
System.out.print("How much is your pay rate?:");
payrate=user.nextInt();
//the code stops here and wont output the rest
biWeekly=(hours*2)*payrate;
weekly=hours*payrate;
switch(payPeriod){
case "weekly":
System.out.println("Your weekly pay is $"+weekly+" Without tax reductions");
break;
case "biweekly":
System.out.println("Your bi-weekly pay is $"+biWeekly+" without tax reductions");
break;
}
}
}
步調試是您的朋友。 – sstan
添加一個'default'語句來打印並看看這個值是什麼 – sidgate
您是否在switch語句之前嘗試打印出payPeriod,和/或調用'payPeriod.trim()'? – Brydenr