Question: If you could please explain code I will upvote thank you! Question 3: Write short code Write a method called findtongeststr that takes two strings,

If you could please explain code I will upvote thank you!

If you could please explain code I will upvote thank you! Question

Question 3: Write short code Write a method called findtongeststr that takes two strings, str1 and str2, and outputs whichever of the two strings is longer. If the two strings are the same length, output a message saying such. The program has been started for you below. Samples: Input: str1 = "really", str2 = "cool" Output: "really" Explanation: "really" is 5 letters, but "cool" is 4 letters Input: str1 = "my", str2 = "mom" Output: "mom" Explanation: "mom" is 3 letters, but " my" is 2 letters Input: str1 = "scary", str2 = "ghost" Output: "Both words are the same length!" Explanation: "scary" and "ghost" both have 5 letters Write your code here: import java.util. Scanner; class Longeststr \{ public void findtongeststr(string str1, String str2) \{ // Your code here \} public static void main(String[] args) \{ Longeststr obj = new Longeststr(); Scanner scan = (System.in); System.out.print("Enter a string:"); String str1 = sanr.next () ; System.out.print "Enter another string:"); String str2 = sanr next () ; obj.findtongeststr (str1, str2); \} \}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!