阶乘函数不起作用 [英] factorial function wont work

查看:135
本文介绍了阶乘函数不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问为什么我的代码会运行没有错误,但它也不会给我一个值。我应该有一个名为total incase的变量facNums值是否被重置?它需要做的是将每个数字相乘,直到循环达到放入的数字,因此如果将5放入文本框,它将变为1 * 2 * 3 * 4 * 5并输出总和。谢谢你们





Hi, I wanted to ask why my code will run with no errors but it wont give me a value either. Should i have a variable called total incase facNums value is being reset? what it needs to do is multiply each number until the loop hits the number put in so if 5 is put in the textbox it will go 1*2*3*4*5 and outputs the sum. Thanks guys


public void facbutton(eventhandler) {
    facnum = (Int.parseInt(string.valueOf(answerBox.getText())));
    if (facNum < 1) {
        MessageBox mb = new MessageBox (fr, "Facorial Error", "Cannot find the factorial of numbers less than 1.");
        mb.show();
    }
    else 
    {
        for (int i=(FacNum -1); i > 1; --i)
            FacNum *= i;
        answerBox.setText(string.valueOf(FacNum()));

推荐答案

你引用三个变量 facnum facNum FacNum ,其中没有一个在代码中定义你已经表明了。难怪没有任何作用。







你有一个函数的调用 FacNum()



我觉得很难相信这甚至编译了,所以我不知道你是如何设法运行的。

[/ edit]
You refer to three variables facnum, facNum and FacNum, none of which is defined in the code you have shown. Little wonder that nothing works.


[edit]
And you have a call to a function FacNum()!

I find it hard to believe that this even compiled, so I don''t know how you are managing to run it.
[/edit]


这篇关于阶乘函数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆