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
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 helloStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started