Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. Write a (static) function public static boolean inarray(String s, String[] SA) that determines if string s is found in String[] SA. for example, if
1. Write a (static) function public static boolean inarray(String s, String[] SA) that determines if string s is found in String[] SA. for example, if SA is {"ab","cd","ef"} and s is "cd", then the function should return true. 2a. Write a function that takes an array of integers and returns its sum. For example, if the array A points to {2,4,6}, then calling sum(A) should return 12. This should be a static function in the same class as main: public static int sum(int[] A) 2b. Write a function to return the smallest string (as determined by the compareTo function) in an array of strings. If the input String[] is empty, return null. public static String smallest(String[] SA) 3. Write a function to reverse a string: public static String reverse(String s) Hint: given a string s, s='a'+s; will add the character 'a' to the front of the string. When writing these functions, do not print inside the function except for debugging. Return the string to be constructed and print where it's called. 3b. A "palindrome" is a string that reads the same forwards and backwards. For example, "noon" and "bob" are palindromes. Write a boolean function that determines if a string is a palindrome (returns true if it's a palindrome and false otherwise): public static boolean palindrome(String s) 4. Write a function to determine if an array of strings contain duplicates. For example, {"ab","cd","ef","cd"} contain duplicates. 5. Write a public static void main that demonstrates these functions.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started