2016-09-20 17 views
-3

私のコードはswitchステートメントを出力しませんでした別のステートメントまたは条件を使用する必要がありますか? switch文までのすべてのことが完全に機能します。Switch Statmentは出力されません。助けて;

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; 

    } 
    } 

    } 
+0

ステップバイステップデバッグはあなたの友人です。 – sstan

+1

'default'文を追加して、値が – sidgate

+0

であることを確認してください。switch文の前にpayPeriodを印刷したり、payPeriod.trim()を呼び出してみましたか? – Brydenr

答えて

-1

正常に動作します。 payPeriod文字列が "週別"または "隔週"、空白なし、大文字と小文字の区別なしの場合にのみケースステートメントに入ります。

+0

は意味があります、私は今、感謝の男を見る –

関連する問題