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: almond pistachio the method findLongest() returns and then the program outputs: pistachio 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
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:
almond pistachiothe method findLongest() returns and then the
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);
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images