Answered step by step
Verified Expert Solution
Link Copied!

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!

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions

Question

How is effective business communication useful to an individual?

Answered: 1 week ago