2016-04-09 5 views
-1

このエラーが発生しており、修正しようとしていません。期待している間にエラー

パッケージbonuscalc;

import java.text.DecimalFormat; import java.util.Scanner;

パブリッククラスBonusCalcは{ /** * @paramは、コマンドライン引数 */ のpublic static無効メイン(文字列[] args){

 Scanner input = new Scanner(System.in); 
    DecimalFormat formatter = new DecimalFormat("#0.00"); 

    int Salary; 
    double NewSal, Comm; 
    double p1 = 0.1; 
    double p2 = 0.15; 
    double p3 = 0.2; 
    double p4 = 0.3; 

    System.out.println("Welcome to Bonus Calculator"); 

    do{ 
     System.out.print("Enter your Salary: "); 
     Salary = input.nextInt(); 
     }While (Salary < 0) 

    if((Salary > 0) && (Salary <= 8000)){ 
     Comm = (Salary * p1); 
     NewSal = Salary + Comm; 
     System.out.print("Your Commition is RM" + formatter.format(Comm)); 
     System.out.println(" and your New Salary is RM" + formatter.format(NewSal)); 

    } 
     else if((Salary > 8000) && (Salary <= 15000)){ 
     Comm = (Salary * p2); 
     NewSal = Salary + Comm; 
     System.out.print("Your Commition is RM" + formatter.format(Comm)); 
     System.out.println(" and your New Salary is RM" + formatter.format(NewSal)); 

    } 
    else if((Salary > 15000) && (Salary <= 25000)){ 
     Comm = (Salary * p3); 
     NewSal = Salary + Comm; 
     System.out.print("Your Commition is RM" + formatter.format(Comm)); 
     System.out.println(" and your New Salary is RM" + formatter.format(NewSal)); 

    } 
    else if(Salary > 25000){ 
     Comm = (Salary * p4); 
     NewSal = Salary + Comm; 
     System.out.print("Your Commition is RM" + formatter.format(Comm)); 
     System.out.println(" and your New Salary is RM" + formatter.format(NewSal)); 

    } 
    else{ 
     System.out.println("Input invalid. Renter Salary"); 

    } 

} 

}

+0

エラーはどうなりますか? –

答えて

2

あなたが持っているの引数whileの代わりにWhileと書かれています。

do { 
... 
} While (Salary < 0); 

正しいは次のようになります。

do { 
... 
} while (Salary < 0); 

これはあなたの問題を解決を願っています。

+0

それは...ありがとう! –

1

do-whileループの構文が無効です。まず、whileは小文字であるため、Whileは正しくありません。さらに、セミコロンがありません。

do { 
    System.out.print("Enter your Salary: "); 
    Salary = input.nextInt(); 
} while (Salary < 0); 

Java変数では、通常、小文字で始まります。それは厳しい規則ではなく、遵守するのが賢明であるという条約です。

関連する問題