基本的Java程序不能在Bluej中运行

时间:2012-10-05 23:22:42

标签: java bluej

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

1 个答案:

答案 0 :(得分:2)

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

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

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