Mein Code würde die switch-Anweisung nicht ausgeben. Muss ich eine andere Anweisung oder Bedingung verwenden? Alles bis zur switch-Anweisung funktioniert perfekt.Switch Statment wird nicht ausgegeben; Hilfe;
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;
}
}
}
Schritt für Schritt Debuggen ist Ihr Freund. – sstan
fügen Sie eine 'default' Anweisung hinzu, um zu drucken und zu sehen, was der Wert ist – sidgate
Haben Sie versucht, payPeriod vor der switch-Anweisung auszudrucken und/oder 'payPeriod.trim()' aufzurufen? – Brydenr