Any help on this problem? I\'ve been working on it for hours and I can\'t get it
ID: 3550339 • Letter: A
Question
Any help on this problem? I've been working on it for hours and I can't get it.
Explanation / Answer
import java.util.Scanner;
public class DoubleLetters
{
public static void main(String[] args)
{
//create scanner object.
Scanner in = new Scanner(System.in);
System.out.println("Enter a line of text :");
// read line of text from user.
String text = in.nextLine();
// start processing each letter
for(int i=0; i<text.length(); i++)
{
// get letter at position i
char ch = text.charAt(i);
// if it is character print double
if(Character.isLetter(ch))
System.out.printf("%c%c",ch,ch);
else if(ch=='!') // if it is exclamatory mark print triple
System.out.printf("%c%c%c",ch,ch,ch);
else // else print single.
System.out.printf("%c",ch);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.