Question
(JAVA) Write a method called padString that accepts two parameters: a string and an integer representing a length. The method should pad the parameter string
(JAVA) Write a method called padString that accepts two parameters: a string and an integer representing a length. The method should pad the parameter string with spaces until its length is the given size It should then RETURN the new string.
For example padString("Hello", 10) should return "Hello " with 5 spaces.
While padString("Hello", 12) should return "Hello " with 7 spaces.
If the size of the string is longer than the word, then no spaces are added, but the word is not shortened.
For example padString("Hello", 3) would return "Hello" with no extra spaces, but the word is still there.
Then your main program should use this padString function on at least 5 different examples and then printing out the result demonstrating that your method works correctly.
Note: For those of you who are working ahead, for this assignment you are not permitted to use an if statement. All work must be done without the use of the if keyword. It can be done.
Step 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