Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java I need to create a simple program that reverses any line of a String using .split method and StringBuilder. We are instructed to

In Java I need to create a simple program that reverses any line of a String using .split method and StringBuilder. We are instructed to use a while loop and was given the hint that it should be done in only 5 lines of code. I posted below what I have, I can't figure out how to implement a while loop using the stringbuilders reverse method to then print out the correct output.

import java.util.Scanner;

public class ReverseAnything{

public static void main(String[] args) {

// Setup a scanner object, and receive user's input

Scanner in = new Scanner(System.in);

System.out.print("Provide an input sentence: ");

String userInput = in.nextLine();

// Step 1: use a split method on the String userInput.

// The argument the split method should be the delimeter " "

//

// Step 1 can be completed in a single line of code.

userInput.split(" ");

System.out.print("The output sentence is : ");

StringBuilder sb = new StringBuilder(userInput);

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

What about leadership lessons from particularly good or bad bosses?

Answered: 1 week ago

Question

When would you use one approach, and when would you use another?

Answered: 1 week ago