Question: Write a program in Java (StringPlay.java) that prompts the user for a string and then prints all of the following: Prints That's my name! if
Write a program in Java (StringPlay.java) that prompts the user for a string and then prints all of the following:
Prints "That's my name!" if the user's string is either your first name or your last name. Prints "Ends in day!" if the last 3 characters in the string are day. Prints the first half of the string.
If the string has an odd number of characters, do not include the middle character.
Prints the second half of the string.
This time, if the string has an odd number of characters, include the middle character.
Prints the ASCII code (in decimal) for the middle character in the string.
For example: if the string is "water", print "The ASCII code for t is 116.". If the string has an even number of characters, print the ASCII code for the character before the middle.
For example: if the string is "wonder", print "The ASCII code for n is 110.".
If the string is empty, print "Empty string.".
Prints the entire string, except for the first 2 characters, unless the first character is 'a' and/or the second character is 'b'.
If the first character is 'a', it should be kept in the string that will be printed. If the second character is 'b', it should be kept in the string that will be printed.
Prints the original string with the last 2 characters swapped.
For example, if the user enters "Antarctica", the program prints "Antarctiac". If the string has less than 2 characters, just print the string.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
