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

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!