Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

SplitString This application accepts an arbitrary number of user inputs. Every time this application receives a string, it should add the string to a growing

SplitString

This application accepts an arbitrary number of user inputs. Every time this application receives a string, it should add the string to a growing string. Newly added strings should be added to the growing string at the index equal to the newly added string's length. If the newly added string's length is equal to or larger than the growing string, this script should add the new string to the end of the growing string. When this application receives a blank input, this application should stop receiving input and print the growing string to the console. The last string that this program should print is the result of the growing string.

Example: input: 'hello' -> growing string: 'hello' input: 'bear' -> growing string: 'hellbearo' input: 'cow' -> growing string: 'helcowlbearo' input: 'disestablishment' -> growing string: 'helcowlbearodisestablishment' input: '' -> growing string: 'helcowlbearodisestablishment'

output: 'helcowlbearodisestablishment'

And my code is following below:

import java.util.Scanner; public class SplitString { public static void main(String[] args) { Scanner input = new Scanner(System.in); String origenInput = input.nextLine(); StringBuffer origenInput1 = new StringBuffer(origenInput); int length = origenInput.length(); while(true) { String userInput1 = input.nextLine(); StringBuffer UserInput1 = new StringBuffer(userInput1); int length2 = userInput1.length(); if (length <= length2) { origenInput1.append(UserInput1); System.out.println(origenInput1); } else { origenInput1.insert(length2, UserInput1); System.out.println(origenInput1); } } } } 

It works well but it does not work well when user type a blank " anyone can help me there?

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 Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions