Answer:
3.) Technology
Explanation:
Technology is pretty epic, my dude.
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
import java.util.Scanner;
public class MyClass1 {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
int smallest = 0, largest = 0, num, count = 0;
while (true){
System.out.println("Enter a number (-1 to quit): ");
num = scan.nextInt();
if (num == -1){
System.exit(0);
}
else if (num < 0){
System.out.println("Please enter a positive number!");
}
else{
if (num > largest){
largest = num;
}
if (num < smallest || count == 0){
smallest = num;
count++;
}
System.out.println("Smallest # so far: "+smallest);
System.out.println("Largest # so far: "+largest);
}
}
}
}
I hope this helps! If you have any other questions, I'll do my best to answer them.