i must create a public static boolean factor(int x, int y) function using public
ID: 3640010 • Letter: I
Question
i must create a public static boolean factor(int x, int y) functionusing
public static void main(String[] args) {
}
public static int add(int x, int y) {
int result = x + y;
return result;
}
public static int sub(int x, int y) {
assert (x >= y);
int result = x - y;
return result;
}
public static int mult(int x, int y) {
if (x == 0 || y == 0) {
return 0;
} else {
int prod = 0;
while (x > 0) {
prod = add(prod, y);
x = sub(x, 1);
}
return prod;
}
}
i cannot use any operators, i have to implement the functions above to get it. Hope someone can help me, thanks.
Explanation / Answer
public static int factor(int count) {
int factor = 1;
for (int i = 1; i <= count; i++) {
factor = mult(factor, i);
System.out.println(i + "! = " + factor);
}
return factor;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.