且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java:阶乘方法?

更新时间:2023-02-19 22:14:18

引用:

有人可以告诉我如何做到这一点吗?

,这是你的HomeWork,而不是我们的。

你已经知道了一切,唯一剩下的就是编写代码了。

想想你的教学内容。

如果您真的找不到自己的解决方案,请与您的老师联系。


查找教科书是否真的很难看到循环看起来像?我会帮你的......



  for (初始化;终止;增量)
{
// 声明
}





你的问题是选择初始化,终止,增量的值,以及对'声明'有用的东西



所以,如果你有一些参数值'n',你觉得什么是'初始化'的好赌注,嗯?如果我说,初始化看起来像



   int  intMultiplier = n; terminate; increment)
{
// 声明在这里
}





就足够了吗?


Implement the factorial method for the given parameter n. Remember that 4!= 4*3*2*1. Use a for loop.

public int p02Factorial(int n) {
  return 0;


Can someone walk me through how to do this?

What I have tried:

public int p02Factorial(int n) {
return 0;

Quote:

Can someone walk me through how to do this?

NO, this is your HomeWork, not ours.
You already know everything, the only thing left is writing the code.
Think about what you have been teached.
If really you can't find a solution yourself, speak with your teacher.


Is it really that hard to look up your textbook to see what a for loop looks like ? I'll help you ...

for (initialisation; termination; increment) 
{
    // statement(s) here
}



your issue is picking values for initialisation, termination, increment, as well as something useful for 'statement(s)'

So, given you're going to have some parameter value 'n', what do you think is a good bet for 'initialisation', hmmm ? what if I said, initialisation looks like

for (int intMultiplier = n; termination; increment)
{
    // statement(s) here
}



is that enough to start with ?