Practical 2 - Strings PDF
Practical 2 - Strings PDF
Write your own version of this method, which will have the following signature:
This means that it will receive two strings as input and return a value of “true” if the
strings are equal, and “false” if they are not.
Use the main method to prompt the user for two strings. After checking if they match
or not, communicate the result to them on the console.
The first two digits give the last two digits of the year a person was born. The next two
give the moth the person was born (01 for January – 12 for December). Finally, the
last two digits are the day the person was born.
Write a main method that will prompt the user to enter their ID number and then use
the displayBirthday(String idNumber) method to display their birthday on the
console.
1
Question 3: How Many?
Write a method howMany(String s, char c) that takes a string and a character
as input and returns the number of times the character occurs in the string. Now use
this method in the main method to count the number of vowels in a string entered
by a user.
Question 4: Shuffle
Write a method shuffle(String s) that receives a string as input and returns that
string with all of the characters mixed up. For example, given the string “Hello”, is
may return “eHoll” or “loHel”.
Test this message by prompting a user in the main method to enter a string to be
garbled. Shuffle this string and display the result to the user.
Question 5: Anagram
Write a method that checks whether two words are anagrams. Two words are
anagrams if they contain the same letters in any order. For example, “silent” and
“listen” are anagrams. The header of the method should be:
Write a test program that prompts the user to enter two strings and tells them
whether the two strings are anagrams or not.