Java在查看正确编码时会返回值吗?

标签 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); 

我试图从一个奇怪的 do while 或 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); 

最佳答案

这是错误的:

totalItems = totalItems++;

你应该这样做

totalItems++;

你所做的等于:

int temp = totalItems;
totalItems = totalItems + 1;// (totalItems++)
totalItems = temp;

关于Java在查看正确编码时会返回值吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6913718/

相关文章:

java - 如何在持久层和领域对象之间正确映射

java - Dijkstra算法-优先级队列问题

java - 如何在android中使用另一个应用程序时停止一个应用程序的服务

java - 如何检查文件是否打开

java - BrowserMob 代理 - WebDriver/错误 : The proxy server is refusing connections

java - IntelliJ : Getting Spring+Gradle+JUnit project to work within IDE

java - 为什么 java.awt.Image 不被视为 java.awt.Component?

java - 这个程序的运行时复杂度是多少?(尤其是 retainAll() 方法)

java - Android PackageStats 始终为零

java - Install4j - 如何在现在是 Mac 文件夹的 Mac 上卸载以前打包的应用程序?