0
import java.util.Scanner;
public class Main {
public static void main (String[]args) {
Scanner input = new Scanner(System.in);
int n, money;
String prodName = null;
String minProdName = null;
double price = 0.0;
double total = 0.0;
double min = 3000.0;
System.out.println ("How much money do you have?");
money = input.nextInt();
System.out.println ("Please, insert the items in the invoice (the name of the product and its price) or enter stop to finish billing ");
prodName = input.next();
while (!(prodName.equals("stop")))
{
price = input.nextDouble();
prodName = input.next();
total = total +price;
if (price<min && !(prodName.equals("stop")))
{
min = price;
minProdName = prodName;
}
}
if (total<money)
System.out.println("You have enough money");
System.out.println();
System.out.printf(" %s is the item with the minimum price(which is KD %.3f)", min);
}
}
我總是得到'停止'作爲產品名稱與最低價格的輸出。我該如何解決這個問題?我沒有得到以下代碼的預期輸出:
@Jens不起作用它仍然給我「一站式」作爲輸出:/ –
Madhurya,你的輸出不匹配你的代碼。不知何故,您正在運行的代碼與您在此顯示的代碼不同。我認爲你應該清理你的編譯目錄並重新編譯一切。 –