Java:阶乘方法? [英] Java: factorial method?

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

问题描述

为给定参数n实现阶乘方法。请记住4!= 4 * 3 * 2 * 1。使用for循环。



  public   int  p02Factorial( int  n){
return 0 ;



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



我是什么尝试过:



public int p02Factorial(int n){

return 0;

解决方案

引用:

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

,这是你的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 ?


这篇关于Java:阶乘方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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