私はこのコードを持っていて、私の人生の中でなぜそれが正しくループしていないのか理解しておらず、製品の量を合計するとwhileループの最初のステートメントだけを読み取るようですそれが引き出すデータ私は最初のwhileステートメントにループし続けるのではなく、同じフレーズで上記のメニューから別の項目を入力してください: "助けていただければ幸いです。このメニューのこのコードを終了しようとしていますが、なぜ正しくループしないのかわかりません。
import java.util.Scanner;
public static void main(String[] args) { //Declare Variables
Scanner input = new Scanner(System.in);
int nProduct = 0; //Stores the value entered by the user
int nPrice = 0; //Stores sum of values entered
int nCount = 0;
int nSum = 0;
double dTax = 0.0;
double dTotal = 0.0;
final int SENTINEL = 10; //Used to end loop
final double TAX = .065;
System.out.print("Please enter the your name: ");
String sName = input.nextLine();
System.out.println("");
System.out.println("BEST PURCHASE PRODUCTS: ");
System.out.println("1. Smartphone $249");
System.out.println("2. Smartphone Case $39");
System.out.println("3. PC Laptop $1149");
System.out.println("4. Tablet $349");
System.out.println("5. Tablet Case $49");
System.out.println("6. eReader $119");
System.out.println("7. PC Desktop $889");
System.out.println("8. LED Monitor $299");
System.out.println("9. Laser Printer $399");
System.out.println("10.Complete my order");
while (nProduct != SENTINEL) {
nSum = nPrice + nSum;
nCount++;
System.out.print("Please enter item from the menu above: ");
nProduct = input.nextInt();
if (nProduct == 1) {
nPrice += 249;
System.out.print("Please enter another item from the menu above: ");
nProduct = input.nextInt();
}
else if (nProduct == 2) {
nPrice += 39;
System.out.print("Please enter another item from the menu above: ");
nProduct = input.nextInt();
}
else if (nProduct == 3) {
nPrice += 1149;
System.out.print("Please enter another item from the menu above: ");
nProduct = input.nextInt();
}
else if (nProduct == 4) {
nPrice += 349;
System.out.print("Please enter another item from the menu above: ");
nProduct = input.nextInt();
}
else if (nProduct == 5) {
nPrice += 49;
System.out.print("Please enter another item from the menu above: ");
nProduct = input.nextInt();
}
else if (nProduct == 6) {
nPrice += 119;
System.out.print("Please enter another item from the menu above: ");
nProduct = input.nextInt();
}
else if (nProduct == 7) {
nPrice += 899;
System.out.print("Please enter another item from the menu above: ");
nProduct = input.nextInt();
}
else if (nProduct == 8) {
nPrice += 299;
System.out.print("Please enter another item from the menu above: ");
nProduct = input.nextInt();
}
else if(nProduct == 9) {
nPrice += 399;
System.out.print("Please enter another item from the menu above: ");
nProduct = input.nextInt();
}
}
dTax = (nPrice * TAX);
dTotal = dTax + nPrice;
System.out.println("");
System.out.println("Thank you for ordering with Best Purchase,"+sName);
System.out.println("Total Items Ordered: " + nCount);
System.out.println("Price of items ordered: $" + nSum);
System.out.println("Sales Tax: $" + dTax);
System.out.println("Total amount due: $" + dTotal);
}
JavaとJavaScriptはまったく異なる言語です。 –