QUESTION IMAGE
Question
write a method max that has two string parameters and returns the larger (i.e., lexically greater) of the two.
Step1: Define the method
public class StringMax {
public static String max(String str1, String str2) {
Step2: Compare the strings
if (str1.compareTo(str2) > 0) {
return str1;
} else {
return str2;
}
}
}Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
public class StringMax {
public static String max(String str1, String str2) {
if (str1.compareTo(str2) > 0) {
return str1;
} else {
return str2;
}
}
}