为什么它会说'{'预计即使它在那里? [英] Why does it say '{' expected even though it is there?
本文介绍了为什么它会说'{'预计即使它在那里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
编译程序后,出现以下错误:
java:11:'{'预期
公共类DebtRatioSwing.Java
^
java:40:'}'预计
}
^
//这两个错误都位于第一个和最后一个花括号。
我尝试过:
import javax.swing.JOptionPane;
公共类DebtRatioSwing.Java
{
public static void main(String [] args)
{
//声明变量
String strMonthlyIncome,strMortgage,strAutoLoan,strOtherDebt;
每月双倍收入,抵押,汽车贷款,其他债务;
//从用户获取输入
strMonthlyIncome = JOptionPane.showInputDialog(null,输入你的月收入:);
strMortgage = JOptionPane.showInputDialog(null,输入抵押贷款的金额:);
strAutoLoan = JOptionPane.showInputDialog(null,输入用于汽车贷款的金额:);
strOtherDebt = JOptionPane.showInputDialog(null,输入花在其他债务上的金额:);
//转换
monthlyIncome = Integer.parseInt(strMonthlyIncome);
mortgage = Integer.parseInt(strMortgage);
autoLoan = Integer.parseInt(strAutoLoan);
otherDebt = Integer.parseInt(strOtherDebt);
//计算
双倍比率=(抵押+ autoLoan + otherDebt)/ monthlyIncome;
//输出
JOptionPane.showMessageDialog(null,你的债务比率是;+(比率)+。,债务比率计算器,JOptionPane.PLAIN_MESSAGE);
System.exit(0);
}
}
解决方案
删除。类名中的字符。
谢谢你们
问题是类名没有正确保存。
Once I compile my program the following error occurs:
java:11: '{' expected
public class DebtRatioSwing.Java
^
java:40: '}' expected
}
^
//Both errors are located at the first and last curly braces.
What I have tried:
import javax.swing.JOptionPane; public class DebtRatioSwing.Java { public static void main(String[] args) { //Declaring Variables String strMonthlyIncome, strMortgage, strAutoLoan, strOtherDebt; double monthlyIncome, mortage, autoLoan, otherDebt; //Get Input from User strMonthlyIncome=JOptionPane.showInputDialog(null, "Enter your monthly income: "); strMortgage=JOptionPane.showInputDialog(null, "Enter amount spent on mortgages: "); strAutoLoan=JOptionPane.showInputDialog(null, "Enter amount spent on automobile loans: "); strOtherDebt=JOptionPane.showInputDialog(null, "Enter amount spent on other debt: "); //Conversions monthlyIncome = Integer.parseInt(strMonthlyIncome); mortgage = Integer.parseInt(strMortgage); autoLoan = Integer.parseInt(strAutoLoan); otherDebt = Integer.parseInt(strOtherDebt); //Calculations double ratio = (mortgage + autoLoan + otherDebt)/ monthlyIncome; //Output JOptionPane.showMessageDialog(null, "Your Debt Ratio is; " + (ratio) + ".", "Debt Ratio Calculator",JOptionPane.PLAIN_MESSAGE); System.exit(0); } }
解决方案
Remove the "." character in the class name.
Thanks guys
The problem was that the class name wasn't saved correctly.
这篇关于为什么它会说'{'预计即使它在那里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文