【问题标题】:Basic Java program wont run in Blue-J基本的 Java 程序不会在 Bluej 中运行
【发布时间】:2012-10-05 23:22:42
【问题描述】:

所以我应该为我的编程课程 Lab 的介绍制作一台自动售货机。到目前为止,这就是我的 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 完成这个实验,任何人都有任何提示?

【问题讨论】:

  • 我们不是来给别人填功课的! (因为作业标签已被弃用......没意义!)

标签: java bluej


【解决方案1】:

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

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

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

【讨论】:

  • 你能帮我解答一下吗?
  • @liam 什么问题?
猜你喜欢
  • 2013-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-05
  • 2012-03-25
  • 2015-06-11
  • 2015-10-18
相关资源
最近更新 更多