Question: Method Definition Write a method called firstTwo that receives a string as its parameter and returns a string made of the first two characters in

 Method Definition Write a method called firstTwo that receives a string

Method Definition Write a method called firstTwo that receives a string as its parameter and returns a string made of the first two characters in the given string. If the given string is "Hello", the method returns "He". If the string length is less than 2, the method returns "@@". Hint 1: You can use the charAt(int index) or substring(int beginlndex, int endlndex) method for getting the first two characters in the given string. firstTwo ("Hello")? "He' firstTwo( "abcdefg")"ab" firstTwo ("ab") "ab" firstTwo("j") " firstTwoc")"ee" 1VI TODO: Write your code here public String firstTwo(String str) f 3 6 8 Submit

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!