Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete the method named Find Second To Last Letter so that it accepts a String

ID: 3690791 • Letter: C

Question

Complete the method named Find Second To Last Letter so that it accepts a String parameter and returns the second-to-last character of that string. For example, if the parameter is "Robert" then "r" would be returned. You are guaranteed as a precondition that the parameter will have a length greater than 1. public static String Find Second To Last Letter(String word)

Explanation / Answer

class findSecondToLastLetter{ public static void main(String args[]){ String str = "He is the one"; String temp = ""; String finalString = ""; for(int i =str.length()-1;i>=0;i--){ temp +=i!=0?str.charAt(i):str.charAt(i)+" "; if(str.charAt(i) == ' '||i==0){ for(int j=temp.length()-1;j>=0;j--){ finalString += temp.charAt(j); } temp = ""; } } System.out.println(finalString); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote