【发布时间】:2017-02-02 14:15:26
【问题描述】:
我正在开发一个程序,但我不明白该程序有什么问题,我试图让它工作,但每次我运行它并输入答案时,它都会在回答。帮助。
import javax.swing.JOptionPane;
public class Furniture
{
public static void main(String args[])
{
String response_1 = JOptionPane.showInputDialog(null, "Type of Table - 1)Pine Wood, 2)Oak, 3)Mahogany");
int type_of_wood = Integer.parseInt(response_1);
String response_2 = JOptionPane.showInputDialog(null, "Size of table - 4)Small, or 5)Large");
int size = Integer.parseInt(response_2);
int price_of_wood = 0;
int price_of_table = 0;
switch(type_of_wood)
{
case 1:
price_of_wood = 100;
break;
case 2:
price_of_wood = 225;
break;
case 3:
price_of_wood = 310;
break;
case 4:
price_of_table = 0;
break;
case 5:
price_of_table = 35;
break;
default:
JOptionPane.showMessageDialog(null, "Unknown Number entered.");
}
JOptionPane.showMessageDialog(null, "The price is " + price_of_wood + price_of_table + " dollars");
}
}
【问题讨论】:
-
"The price is " + price_of_wood + price_of_table + " dollars"这可能是问题所在。您的整数在输出中是一种“添加”。试试"The price is " + price_of_wood += price_of_table + " dollars"。它可能会解决您的问题
标签: java computer-science