所以我不确定该做什么我已经做过 / * *要完成的方法集合 *完成给定方法的每个TODO正文代码 *对第一种方法和最后一种方法使用递归 * /
public class Methods
/*
* method to compute value of f(n) where:
* f(1) = 1
* f(n) = n + f(n-1) for n>1, n is even
* f(n) = n * f(n-1) for n>1, n is odd
*/
public static int f(int n) {
//TODO
return 0; //dummy line, replace this
}
/*
* method to compute the sum of the proper divisors of a given positive integer, n
* e.g., if n is 12, the sum of the proper divisors is:
* 1 + 2 + 3 + 4 + 6 = 16
* note: proper divisors are all divisors of an integer other than itself
*/
public static int sumOfDivisors(int n) {
//TODO
return 0; //dummy line, replace this
}
/*
* method that returns a String indicating whether a given positive integer, n, is:
* "abundant" - sum of proper divisors is greater than n
* "deficient" - sum of proper divisors is less than n
* "perfect" - sum of proper divisors is equal to n
*/
public static String numberType(int n) {
//TODO
return "foo"; //dummy line, replace this
}
/*
* method that returns the sum of the digits of the positive integer, n
* e.g., if n = 5403, the method will return:
* 5+4+0+3 = 12
* note: the right-most (1's) digit can be found using n%10
* the remaining digits (all but the 1's digit) can be found using n/10
*/
public static int sumOfDigits(int n) {
//TODO
return 0; //dummy line, replace this
}
//a dummy main method, not used
public static void main(String[] args) {
System.out.println("This program is not meant to be run on its own.");
System.out.println("This is just a dummy main method.");
}
} //end Methods
所以,任何帮助都会很棒。
答案 0 :(得分:0)
所以我不确定该怎么做我已经做过的事情
您实际上只编写了方法声明。
您的任务记录真实,您可以尝试实施这些实用程序(如public int[] divisors(int n)
等)并最终返回此处并询问您的疑虑,发布代码或错误。
PS:这似乎是一项学术任务,你检查了一些书籍或笔记吗?