Screen Shot 2
Screen Shot 2
java
package project;
import java.util.Scanner;
do {
System.out.println();
System.out.printf("| %-2s | %-36s |\n", "Numper", "Operation");
System.out.println("==============================================");
System.out.printf("| %-2s | %-40s |\n", "1", "Addition of two numbers");
System.out.printf("| %-2s | %-40s |\n", "2", "Subtraction of two numbers");
System.out.printf("| %-2s | %-40s |\n", "3", "Multiplication of two numbers");
System.out.printf("| %-2s | %-40s |\n", "4", "Division of two numbers");
System.out.printf("| %-2s | %-40s |\n", "5", "Modulus (a % b)");
System.out.printf("| %-2s | %-40s |\n", "6", "Power (a^b)");
System.out.printf("| %-2s | %-40s |\n", "7", "Square root of x");
System.out.printf("| %-2s | %-40s |\n", "8", "Factorial of a number");
System.out.printf("| %-2s | %-40s |\n", "9", "Log(n)");
System.out.printf("| %-2s | %-40s |\n", "10", "Sin(x)");
System.out.printf("| %-2s | %-40s |\n", "11", "Absolute value (|x|)");
System.out.printf("| %-2s | %-40s |\n", "12", "Average of numbers in array");
System.out.printf("| %-2s | %-40s |\n", "0", "Close");
System.out.println("==============================================");
choice = input.next();
switch (choice) {
case "1":
addition(input);
break;
case "2":
subtraction(input);
break;
case "3":
multiplication(input);
break;
case "4":
division(input);
break;
case "5":
modulus(input);
break;
case "6":
power(input);
break;
case "7":
squareRoot(input);
break;
case "8":
factorial(input);
break;
case "9":
log(input);
break;
case "10":
sin(input);
break;
case "11":
absolute(input);
break;
case "12":
average(input);
break;
case "0":
System.out.println("!Turn Off!");
break;
default:
System.out.println("Invalid choice.");
break;
}
} while (!choice.equals("0"));
}
}
}
}
}
}
}
}
}
}
}
}
}
}
if (num >= 0) {
long result = 1;
for (int i = 2; i <= num; i++) {
result *= i;
}
System.out.println("Result: " + result);
} else {
System.out.println("Factorial is not defined for negative numbers.");
}
} catch (Exception e) {
System.out.println("Invalid input for factorial.");
}
}
}
}
}
}
}}