Question Index

Write a program to reverse each word in a sentence. There should not be any extra spaces at the end.

Input (String) Output (String)
I love mom mom love I
I like my brother brother my like I
Sun rises in the east east the in rises Sun
Learn Java with Merit Campus Campus Merit with Java Learn
India won world cup in 2011 2011 in cup world won India

class ReverseWordsInASentence
    public static void main(String s[])
        String sentence = "I love mom";
        System.out.println("After reversing words : " + reverseWords(sentence));


    public static String reverseWords(String sentence) {




Topic: Additional String Methods in Java

Read this topic
Take test on this topic

Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App