JAVA编译提示java:34: error: 'else' without 'if'
不知道错在哪里?//HouseSign.java-Thisprogramcalculatespricesforcustomhousesigns.publicclassHo...
不知道错在哪里?
// HouseSign.java - This program calculates prices for custom house signs.
public class HouseSign
{
public static void main(String args[])
{
// This is the work done in the housekeeping() method
// Declare and initialize variables here.
double charge;
String color_char;
String wood_type;
int basis_letter;
double min_charge= 30.00;
double color_charge=12;
double wood_typeCharge=15;
double letter_Charge=3;
double add_charge;
double chr_charge;
// Charge for this sign.
charge= min_charge + add_charge;
// Number of characters.
basis_letter = 8;
// Color of characters.
color_char="gold";
// Type of wood.
wood_type = "oak";
// This is the work done in the detailLoop() method
// Write assignment and if statements here as appropriate.
if (color_char.equals("gold"));
color_charge=12;
else if(wood_type.equals("oak"));
wood_typeCharge=15;
else if(basis_letter = 8);
chr_charge=letter_Charge*2;
else
add_charge=color_charge+wood_typeCharge+chr_charge;
// This is the work done in the endOfJob() method
// Output Charge for this sign.
System.out.println("The charge for this sign is $" + charge);
System.exit(0);
}
} 展开
// HouseSign.java - This program calculates prices for custom house signs.
public class HouseSign
{
public static void main(String args[])
{
// This is the work done in the housekeeping() method
// Declare and initialize variables here.
double charge;
String color_char;
String wood_type;
int basis_letter;
double min_charge= 30.00;
double color_charge=12;
double wood_typeCharge=15;
double letter_Charge=3;
double add_charge;
double chr_charge;
// Charge for this sign.
charge= min_charge + add_charge;
// Number of characters.
basis_letter = 8;
// Color of characters.
color_char="gold";
// Type of wood.
wood_type = "oak";
// This is the work done in the detailLoop() method
// Write assignment and if statements here as appropriate.
if (color_char.equals("gold"));
color_charge=12;
else if(wood_type.equals("oak"));
wood_typeCharge=15;
else if(basis_letter = 8);
chr_charge=letter_Charge*2;
else
add_charge=color_charge+wood_typeCharge+chr_charge;
// This is the work done in the endOfJob() method
// Output Charge for this sign.
System.out.println("The charge for this sign is $" + charge);
System.exit(0);
}
} 展开
3个回答
展开全部
if (color_char.equals("gold"));
这后面的分号去掉。
else if 后面的分号也要去掉。
另外,add_charge,chr_charge没有初始化就调用了。
最后,else if(basis_letter = 8)请改为else if(basis_letter == 8)
希望对你有帮助。
这后面的分号去掉。
else if 后面的分号也要去掉。
另外,add_charge,chr_charge没有初始化就调用了。
最后,else if(basis_letter = 8)请改为else if(basis_letter == 8)
希望对你有帮助。
追问
谢谢你!add_charge,chr_charge该如何修改初始化它们,还是这两个根本就是多余的。我实在是糊涂了,想不明白!
追答
你的程序中有这么两句:
double letter_Charge=3;
double add_charge;
其中,第一句声明了变量letter_Charge,并初始为它的值为3.
而第二句只声明了变量add_charge,并没初始化,也就是add_charge还没有值。
因为你的程序中有下面两句:
charge= min_charge + add_charge;
add_charge=color_charge+wood_typeCharge+chr_charge;
两句中,分别用到了add_charge和chr_charge,故add_charge和chr_charge不是多余的。
呵呵,这么说,你应该知道如何初始化了吧。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询