Answer to Question #235730 in Java | JSP | JSF for guru

Question #235730

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


1
Expert's answer
2021-09-10T18:52:04-0400


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);
    }
    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS