缺少大括号,但我从来没有错过它(Java)



当我输入"if conditional"对不起,带来了完整的代码,但我已经试图找到什么是错误的一整天,但我仍在寻找问题。

import javax.swing.JOptionPane;
class Accounting2 {
public static double VOS;
public static double vatRate = 0.1;
public static double expenseRate = 0.3;

public static double person1, person2, person3;
public static double[] dividend = new double[3];

public static void printReport(double person1, double person2, double person3) {
System.out.println("Value of supply : " + VOS);
System.out.println("VAT : " + getVAT());
System.out.println("Price : " + getPrice());
System.out.println("Income : " + getIncome());
System.out.println("Person1 : " + person1 +
"nPerson2 : " + person2 +
"nPerson3 : " + person3);
}

public static double getIncome() {
return VOS - getExpense();
}
public static double getExpense() {
return VOS * expenseRate;
}
public static double getPrice() {
return VOS + getVAT();
}
public static double getVAT() {
return VOS * vatRate;
}

public static double toPutGetIncome = getIncome(); // error hapeens here (Syntax error on token ";", { expected after this token)

// The "if conditional" starts from here
if( toPutGetIncome >= 10000 ) {
for (int n = 0; n < 3; n++) {
dividend[n] = Double.parseDouble(JOptionPane.showInputDialog("Enter a Dividend of Person" + (n+1)));
if(dividend[0] + dividend[1] + dividend[2] > 1) { System.out.println("Dividend over"); return; }
}
if(dividend[0] + dividend[1] + dividend[2] < 1) { System.out.println("Dividend short"); return; }
}


if( toPutGetIncome < 10000 ) { person1 = getIncome(); person2 = 0; person3 = 0; }
else{ person1 = getIncome()*dividend[0]; person2 = getIncome()*dividend[1]; person3 = getIncome()*dividend[2]; }
// ends

}
public class AccountingApp2 {
public static void main(String[] args) {

Accounting2.VOS = Double.parseDouble(JOptionPane.showInputDialog("Enter a VOS"));
if( Accounting2.VOS <= 0 ) { System.out.println("Wrong VOS"); return; }

Accounting2.printReport(Accounting2.person1, Accounting2.person2, Accounting2.person3);

}
} // the other error happens here (Syntax error, insert "}" to complete ClassBody)

我不确定它对你有帮助。我在学习外班和内班。所有的代码都在公共类AccountngApp2中。我制作了另一个类Accounting2来移动AccountingApp2的方法,当我移动方法时发生了错误。

// The "if conditional" starts from here
if( toPutGetIncome >= 10000 ) {
for (int n = 0; n < 3; n++) {
dividend[n] = Double.parseDouble(JOptionPane.showInputDialog("Enter a Dividend of Person" + (n+1)));
if(dividend[0] + dividend[1] + dividend[2] > 1) { System.out.println("Dividend over"); return; }
}
if(dividend[0] + dividend[1] + dividend[2] < 1) { System.out.println("Dividend short"); return; }
}


if( toPutGetIncome < 10000 ) { person1 = getIncome(); person2 = 0; person3 = 0; }
else{ person1 = getIncome()*dividend[0]; person2 = getIncome()*dividend[1]; person3 = getIncome()*dividend[2]; }
// ends

无效。if语句必须在方法、构造函数或静态初始化项中。

最新更新