Hey guys! So I'm asked to make a piece of code that takes a string of text that a user inputs and print to the console the same string but with each letter doubled and each '!' tripled.
Example: hey, guys! ---> hheeyy, gguuyyss!!!
I have made the code below so far, and it works, however I need to be able to triple the '!' while having commas and other special characters remain at 1! I have tried adding more if-statements but it seems to only break the output even more. Any help would be appreciated. Thank you!!!
So far, I will input "hey, guys!" and receive "hheeyy, gguuyyss!" (I need the '!' tripled without doubling the comma.
import java.util.Scanner; public class DoubleLetters { public static void main (String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Please type a sentence:"); String input = scan.nextLine(); int length = input.length(); String newString = ""; for(int j = 0; j < length; j++) { if(Character.isLetter(input.charAt(j))) newString = newString + input.charAt(j) + input.charAt(j); else newString = newString + input.charAt(j); } System.out.println(newString); } }
--- Update ---
I've been thinking and I think the only way I can do this is with another if-statement. I'm not sure if I should put it right after the first if-statement or after the else