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

标签 java bluej

所以我应该为我的编程类(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/

相关文章:

java - 实例化对象

java - Jackson 多态类型处理 - 属性被丢弃

java - 我应该如何克隆嵌套 ArrayList?

java - 在 while 循环中停止重复的 Println,BlueJ

java - 为什么 HTML 图像标签在文件协议(protocol)中不起作用?

java - 线程中的异常 "main"java.lang.ArrayIndexOutOfBoundsException : -1

java - 获取 Java 中的完整语言名称列表

java - 二维数组索引越界;创建与参数大小相同的新二维数组?

java - 计算胜/负、胜率和总胜率

java - BlueJ 数组列表参数。