Respuesta :
Answer:
import java.util.Scanner;
public class Question {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter first string: ");
String first = scan.nextLine().toLowerCase();
System.out.println("Enter second string: ");
String second = scan.nextLine().toLowerCase();
maxOfTwoString(first, second);
}
public static void maxOfTwoString(String firstString, String secondString){
if((firstString.compareTo(secondString)) < 0){
System.out.println(secondString);
} else if ((firstString.compareTo(secondString)) > 0){
System.out.println(firstString);
}
}
Explanation:
First, the import statement was use to import the Scanner class which allow user to enter input.
Then, the class was defined named Question
The main function was also defined. Then, the scanner object 'scan' was declared and initialized.
After that, the user was prompt to enter first string, which was assigned to 'first', then the user is also prompt to enter second string, which was assigned to 'second'. As the input are been collected from the user, they are also converted to lowercase for ease comparison. They are converted to lowercase before been assigned to first and second. The two string (first and second) are passed as arguments to the function 'maxOfTwoString'.
The maxOfTwoString function is defined and the two string is compared using Java String compareTo method. If a compareTo b is less than zero; it means b is greater. And if a compareTo b is greater than zero; it means a is greater. The function also output the string that is greater.