Q - Write a Java program that reverses the order of words in a given sentence.
import java.awt.*;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
import static java.lang.System.in;
public class demo {
public static void main(String[] args) {
String str = "My name is Gulshan";
String[] arr = str.split(" ");
int arrLen = arr.length;
List<String> result = new ArrayList<>();
for (int i=(arrLen-1); i>=0; i--){
result.add(arr[i]);
}
System.out.println("Original String: " + str);
System.out.print("String after reverse: " );
for (String a:result) {
System.out.print(a + " ");
}
}
}