public static void main(String[] args)
{
// declares variables
int items, time;
double heat, h1, h2, h3, h4;
h1 = 1.00;
h2 = 1.25;
h3 = 1.50;
h4 = 2.00;
Scanner num = new Scanner(System.in);
// asks user to input the amount of items to heat and the amount of time to
heat the items
System.out.println("Select number of items being heated");
items = num.nextInt();
System.out.println("Select amount of time in seconds to heat one item");
time = num.nextInt();
// gets user to re-enter the amount of items to less than 5
while (items > 4)
{
System.out.println("warning: more than four items is too hot!
\nplease enter a number below 5");
items = num.nextInt();
}
//heating calculations
switch (items)
{
case 1:
heat = h1;
break;
case 2:
heat = h2;
break;
case 3:
heat = h3;
break;
case 4:
heat = h4;
default:
heat = 1;
}
// outputs the total time
System.out.println("Time: " + time * heat * items + " seconds");
}
}
任何帮助都会是伟大的家伙!这是一个学校项目,它说"加热"尚未初始化
答案 0 :(得分:0)
你必须在代码中修改3行:
1.你忘记评论热量项目
//加热物品
你忘了加热后加上引号!“
你忘记在单词之前添加加号和引号。你需要添加符号才能用两行写一个字符串:
System.out.println(“警告:超过四个项目太热了!”
+ "\nplease enter a number below 5");