Question: Java Program Write a program in a single class called DoubleLetters that does the following: The program should read in a single line of text
Java Program
Write a program in a single class called DoubleLetters that does the following:
The program should read in a single line of text from the keyboard. It should then print to the console the same line of text with these changes: Letters should be doubled. Exclamation points (!) should be tripled. All other characters appear as they do in the input string.
The objectives of this assignment are to:
Be able to read text input from the keyboard using a Scanner object.
Be able to traverse the characters in a String using String class methods and a for loop.
Be able to use an if statement in a loop.
Example 1: if the input text is:
Hey! My car can't move!!
Then your program should print:
HHeeyy!!! MMyy ccaarr ccaann'tt mmoovvee!!!!!!
Example 2: if the input text is:
Hello, I have 9 of them!
Then your program should print:
HHeelllloo, II hhaavvee 9 ooff tthheemm!!!
note: concatenating a char onto a String requires that you add an empty String so the char is treated as a character and not a number. Example: newStr = newStr + "" + curChar;
Another approach: simply print the answer character by character as you traverse the input string.
Hint: When is a character a letter? There is more than one way to tell. Look up the Character class in the Java API. There is a method that would be very helpful.
Submit your code for the DoubleLetters class below. Do NOT include import statements in your submission. We import the Scanner class for you.
import java.util.Scanner;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
