gpt4 book ai didi

java - 我没有得到以下代码 : 的预期输出

转载 作者:行者123 更新时间:2023-12-01 20:27:44 26 4
gpt4 key购买 nike

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

}
}

我总是得到“停止”作为具有最低价格的产品名称的输出。我该如何解决这个问题?

预期输出:
Expected Output

我的输出:
My Output

最佳答案

System.out.printf(" %s is the item with the minimum price(which is KD %.3f)", min);

这里您只传递一个要打印的值。您应该在此处传递两个值。第一个为 String,第二个为 Double

因此将此行更改为

System.out.printf(" %s is the item with the minimum price(which is KD %.3f)", minProdName, min);

关于java - 我没有得到以下代码 : 的预期输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43655206/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com