Create a program that when given a four word sentence as CMD arguments, it prints it backwards. E.g the sentence “How are you Today”, will be printed as “Today you are How”. Sample run 1: Sample run 2: java lab02_task01 how are you today java lab02_task01 we are going home Output: today you are how Output: home going are we
package stringreverse;
public class StringReverse {
public static void main(String[] args) {
String inputTest = "How are you Today";
String outputTest = "";
String[] arr = inputTest.split(" ");
for(int x = arr.length-1; x >= 0; x--)
{
outputTest += arr[x];
if (x != 0) { outputTest += " "; }
}
System.out.println(outputTest);
}
}
Comments
Leave a comment