Coding question in interview: Input: "i am kiran. i am arjun." Output:"kiran am i. arjun am i."
Sigiloso
class Main { public static void main(String[] args) { String str = "i am kiran. i am arjun."; // Split the string by periods String[] sentences = str.split("\\."); StringBuilder sb = new StringBuilder(); for (String sentence : sentences) { if (!sentence.trim().isEmpty()) { // Split the sentence into words and reverse them manually String[] words = sentence.trim().split("\\s+"); for (int i = words.length - 1; i >= 0; i--) { sb.append(words[i]); if (i > 0) { sb.append(" "); } } sb.append(". "); } } // Trim the final result to remove any extra trailing space String result = sb.toString().trim(); System.out.println(result); } }