[英]Switch Statement won't output;
我的代碼不會輸出 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;
}
}
}
它工作正常。 請記住,只有當 payPeriod String 與“weekly”或“biweekly”完全相同,沒有空格,沒有大寫等時,它才會進入 case 語句。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.