Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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!
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started