2017-03-20 50 views
0

所以我有这段代码,我只想要选项2在选项1的值不是0时执行。如果它有0,则抛出一个错误。任何帮助表示赞赏。谢谢! :)如果第一条语句= 0,则不要继续

if (option == 1){ 
    System.out.println("YOU HAVE SELECTED OPTION 1"); 
    System.out.println(accounts[i].getOwner().getfirstName() + " " + accounts[i].getOwner().getlastName() + ", Please enter your yearly salary:"); 
     accounts[i].setyearlySalary(in.nextDouble());  
} 
else if (option == 2){ 
     System.out.println("YOU HAVE SELECTED OPTION 2"); 
     System.out.println(accounts[i].getOwner().getfirstName() + " " + accounts[i].getOwner().getlastName() + ", Please enter any additional salary:"); 

     accounts[i].setotherSalary(in.nextDouble()); 

} 
+1

你是在做你说什么地方卡住? – emaillenin

+0

我在选项2后尝试了一些if(accounts [I] .setyearlySalary == 0){System.out.println(“错误:如果选项1为零,则无法继续);}但它表示void不能转换为布尔值 – icewolf461

+0

@ icewolf461为什么你在使用setter而不是getter在条件为 “accounts [I] .setyearlySalary == 0”? –

回答

0

我会建议你创建一个函数来设置附加工资和称它为选项2代码和情况下,如果选择1 == 0,