5.25 LAB: Longest string (EO)
Write a method, findLongest(), that takes two strings as parameters and returns the longest string. If the strings are the same length then return the second string.
Ex. If the input is:
the method findLongest() returns and then the program outputs:
Your program must define the following method:public String findLongest(String str1, String str2)
import java.util.Scanner;
public class LongestString {public String findLongest(String str1, String str2) {/* Type your code here. */}
public static void main(String[] args) {LongestString mainObject = new LongestString();Scanner scnr = new Scanner(System.in);String str1;String str2;String longest;str1 = scnr.next();str2 = scnr.next();longest = mainObject.findLongest(str1, str2);System.out.println(longest);}}
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here