// ProgrammingEx5_2.java
public class ProgrammingEx5_2 {
// Method 1: Calculate the sum of two numbers
public static int calculateSum(int a, int b) {
return a + b;
}
// Method 2: Find the maximum number from an array
public static int findMax(int[] array) {
int max = array[0];
for (int i = 1; i < array.length; i++) {
if (array[i] > max) {
max = array[i];
}
}
return max;
}
// Method 3: Check if a string is a palindrome
public static boolean isPalindrome(String s) {
String reversed = new StringBuilder(s).reverse().toString();
return s.equals(reversed);
}
// Method 4: Calculate the factorial of a number
public static int calculateFactorial(int n) {
if (n == 0) {
return 1;
} else {
return n * calculateFactorial(n - 1);
}
}
// Method 5: Convert a string to uppercase
public static String convertToUppercase(String s) {
return s.toUpperCase();
}
}