Java Reference
In-Depth Information
11. 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 length. For example,
padString("hello", 8) should return "hello " . (This sort of method is useful when trying to print output
that lines up horizontally.) If the string's length is already at least as long as the length parameter, your method
should return the original string. For example, padString("congratulations", 10) should return
"congratulations" .
12. Write a method called vertical that accepts a string as its parameter and prints each letter of the string on separate
lines. For example, a call of vertical("hey now") should produce the following output:
h
e
y
n
o
w
13. Write a method called printReverse that accepts a string as its parameter and prints the characters in opposite
order. For example, a call of printReverse("hello there!") should print "!ereht olleh" . If the empty
string is passed, the method should produce no output.
14. Write a method called inputBirthday that accepts a Scanner for the console as a parameter and prompts the user
to enter a month, day, and year of birth, then prints the birthdate in a suitable format. Here is an example dialogue
with the user:
On what day of the month were you born? 8
What is the name of the month in which you were born? May
During what year were you born? 1981
You were born on May 8, 1981. You're mighty old!
15. Write a method called processName that accepts a Scanner for the console as a parameter and prompts the user to
enter a full name, then prints the name in reverse order (i.e., last name, first name). Here is an example dialogue with
the user:
Please enter your full name: Sammy Jankis
Your name in reverse order is Jankis, Sammy
Programming Projects
1. Write a program that produces images of Christmas trees as output. It should have a method with two parameters:
one for the number of segments in the tree and one for the height of each segment. For example, the tree shown here
Search WWH ::




Custom Search