Answer:
public static int factorial(int n) {
if (n >= 1 && n <=12) {
if (n==1)
return 1;
else
return n * factorial(n-1);
}
else
return -1;
}
Explanation:
Create a method called factorial that takes one parameter, n
Check if n is n is between 1 and 12. If it is between 1 and 12:
Check if it is 1. If it is 1, return 1. Otherwise, return n * function itself with parameter n-1.
If n is not between 1 and 12, return -1, indicating that the number is not in the required range.
For example:
n = 3 Is n==1, NO factorial(3) = n*factorial(2)
n = 2 Is n==1, NO factorial(2) = n*factorial(1)
n = 1 Is n==1, YES factorial(1) = 1.
Then factorial(2) = 2*1 = 2, factorial(3) = 3*2 = 6
Answer:
oky will do. Have a good day
Answer:
# Instead of repeating code over and over
forward(10)
left(90)
forward(10)
left(90)
forward(10)
left(90)
forward(10)
left(90)
# Use a for loop to repeat the code!
for i in range(4):
forward(10)
left(90)
# You can use the i variable inside the loop
# i starts at 0, and goes up to COUNT-1
# This will make Tracy move forward 0, then 1, then 2
for i in range(3):
forward(i)
# You can change the value of i inside a for loop by using mathematical expressions
for i in range(3):
forward(i*10)
# You can also control the value of i by using extended parameters
for i in range(STARTING_VALUE, ENDING_VALUE, INCREMENT):
# This will move Tracy forward 25, 50, and 75 pixels
for i in range(25, 76, 25):
forward(i)
love you guys <3
IDE: Integrated drive electronics
Sata:Serial advance technology attachment