gpt4 book ai didi

java - 基本 Java 程序无法在 Bluej 中运行

转载 作者:行者123 更新时间:2023-12-02 07:32:14 24 4
gpt4 key购买 nike

所以我应该为我的编程类(class)实验室入门制作一台自动售货机。到目前为止,这就是我的 Java 代码的样子。

import java.util.Scanner;
public class VendingMachine
{
public static void main (String[] args)
{
Scanner keyboard = new Scanner(System.in);

final int quarter = 25;
final int dime = 10;
final int nickel = 15;
int cost = keyboard.nextInt ();

int totalChange = 100 - cost;
int totalQuarters= totalChange/quarter;
totalChange = totalChange % quarter;
int totalDimes = totalChange/dime;
totalChange = totalChange % dime;
int totalNickels = totalChange/nickel;
totalChange = totalChange % nickel;

System.out.print("Enter Price for your item" + "30" );

}
}

我需要它做的就是这个。

Enter a price for item (from 25 cents to a dollar, in 5-cent increments): 45


You bought and item for 45 cents and gave me a dollar, so your change is

2 quarters,

0 dimes, and

1 nickels.

使用值 30 、 65 和 100 。由于某种原因,该程序不会在 Blue J 中启动。所以我知道建议使用 Eclipse,但我想我想用 Blue J 完成这个实验,任何人都有任何提示?

最佳答案

我的猜测是程序正在启动,但您没有意识到它,因为它正在等待输入。

将包含 System.out.print("Enter Price for your item"+ "30"); 的行移至 keyboard.nextInt 扫描上方以进行输入。就像这样:

System.out.print("Enter Price for your item" + "30" );
int cost = keyboard.nextInt ();

关于java - 基本 Java 程序无法在 Bluej 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12755262/

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