嘿所以我需要计算一个数字的系数,我插入到我的第一个文本区域,但是当我点击按钮时,它给了我0。有人可以帮助PLZ吗?不胜感激。我也没有在Java中,所以如果你看到的东西,以提高PLZ份额:)java计算插入数字的能力
FIX向下跌破
嘿所以我需要计算一个数字的系数,我插入到我的第一个文本区域,但是当我点击按钮时,它给了我0。有人可以帮助PLZ吗?不胜感激。我也没有在Java中,所以如果你看到的东西,以提高PLZ份额:)java计算插入数字的能力
FIX向下跌破
必须使用教师法first.Try这个初始化变量FAC:
public void actionPerformed(ActionEvent e) {
int temp = Integer.parseInt(textFiled1.getText());//keep in mind that if the text is not a number this will give you an error
fac = faculty(temp);
textField2.setText("" + fac);
}
你也必须修改教师法:
TextField textField1, textField2;
Button btn;
static int fac;
public static int faculteit(int n) {
int temp = 1;//this is a temporal variable that we use to compute the output of this method
for (int i = 1; i <= n; i++)
{
temp*= i;
}
return temp;
}
请初始化变量FAC为1 你用0乘以数字和它返回结果为0。
内faculteit方法和之前的循环,
fac = 1;
你永远不会调用'faculteit'和'fac'没有初始化,所以它会保持0,即使你调用该方法。 – Eran
“教师”是指“阶乘”吗? – khelwood