Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Write a complete Java program called PadString that takes as input a String and an integer value and pads the string with blank spaces

Problem

Write a complete Java program called PadString that takes as input a String and an integer value and pads the string with blank spaces until the given length is reached.

Overview

Your program should prompt the user to enter a String. Save this in a variable called word

It should next prompt for a length. Save this in an integer called length.

Your program should add blank spaces to word at the beginning until its new length reaches the length that was given by the user. (In the display the blank is shown as to make counting blanks easy and visible)

If the given length is less than the length of the given work, then the word remains intact. If the length is larger, then - is added to the word at the beginning until its length reaches the given length. Look at the output given to you. The program has been tested three times with three separate input values.

So for example, if the input word was program and length was -1, the result should be program

If the input word was program and length was 2, the result should be program

If the input word was program and length was 8, the result should be ----program

image text in transcribed

Please enter a string hello Please enter the length of the result string 0 The resulting string is hello Please enter a string hello Please enter the length of the result string 10 The resulting string is -----hello Please enter a string hello Please enter the length of the result string 5 The resulting string is hello

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

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

More Books

Students also viewed these Databases questions

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago