0 java
我的问题是关于增量我问你如何从do while循环返回数据,假设要在每个值中设置.
我的do while循环中的totalSales应该在循环出来时有数据集,它不会将数据保存到totalSales或totalItems值中.
// The system print out values are empty.
System.out.printf(salesID + " you entered a total of: " + totalItems + "With a total sales of $%15.2f" + totalSales);
Run Code Online (Sandbox Code Playgroud)
我试图从一个怪异的do或if语句循环返回数据,它不会返回我设置的项目为什么?
// yesno to n for first loop through.
do {
System.out.println("Welcome Sales ID: " + salesID + " please enter the samsung TV sold: \n");
samsungProduct = scanValue.next();
System.out.println("Please enter your total TV sales amounts individually for today \n");
singleSale = scanValue.nextDouble();
totalSales = totalSales + singleSale;
totalItems = totalItems++;
System.out.println("Do you want to enter another sales total(Y/N): \n ");
yesNo = scanValue.next();
} while (!yesNo.equalsIgnoreCase("N"));
// get the items set inside of the do while loop.
// The system print out values are empty.
System.out.printf(salesID + " you entered a total of: " + totalItems + "With a total sales of $%15.2f" + totalSales);
Run Code Online (Sandbox Code Playgroud)
这是错的:
totalItems = totalItems++;
Run Code Online (Sandbox Code Playgroud)
你应该做
totalItems++;
Run Code Online (Sandbox Code Playgroud)
你做了什么等于:
int temp = totalItems;
totalItems = totalItems + 1;// (totalItems++)
totalItems = temp;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
307 次 |
| 最近记录: |