Question: 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

Problem Write a complete Java program called PadString that takes as input

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!