Reverse String Java Interview Question

Day 4 One of the questions from my recent interview was to reverse each word in a string. It’s a small problem, but it really makes you think about string manipulation and iteration. Simple problem, but good test of core concepts ================================================= // Online Java Compiler // Use this editor to write, compile and run your Java code online class Main {   public static void main(String[] args) {           String s="Hello world from java language";           String [] words=s.split(" ");           String revString="";           for(String w:words)     {       String reverseWord="";               for(int i=w.length()-1; i>=0;i--)       {         reverseWord=reverseWord+w.charAt(i);       }               revString=revString+reverseWord+" ";             }     System.out.println(revString);   } } Output :olleH dlrow morf avaj egaugnal #Java #InterviewQuestion #CodingPractice #Learning #Developers

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories