Monday, 2 May 2022

Reverse the words in a sentence using Java

 Reverse the words in a sentence using Java


        public void reverseWordsInString() {

String input="Welcome to my coding",output="";

String[] inputArray=input.split(" ");

for(String str:inputArray) {

output=str+" "+output;

}

System.out.println(output);

}


O/P: coding my to Welcome 

No comments:

Post a Comment

Switch case in Java

 Problem statement: Return the capital of a state based on input state          public String getCapital(String state){               switch...