import java.util.*;
public class lampWatt {
public static void main (String [] args)
{
Scanner x=new Scanner(System.in);
int number;
System.out.println("Enter number of bulbs");
number = x.nextInt();
int wattage;
System.out.println("Enter wattage");
wattage = x.nextInt();
switch(number) {
case 5 :
System.out.println("Total price is"+" "+ number*50);
break;
case 10 :
System.out.println("Total price is"+" "+ number*262);
break;
case 15 :
System.out.println("Total price is"+" "+ number*271);
break;
case 30 :
System.out.println("Total price is"+" "+ number*401);
break;
default :
System.out.println("Invalid Wattage");
}
}
}
样本输入: 输入灯泡数量:2 输入瓦数(5/10/15/30):30 样本输出:
样本输入: 输入灯泡数量:1
样本输出: 瓦数不正确
答案 0 :(得分:2)
我相信switch(number)
应该是switch(wattage)
-因为您的价格是基于瓦数的,并且默认的无效瓦数消息不适用于订购的灯泡数量。