English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Ex: I love to eat food -> Iay loveay toay eatay fooday

2007-07-09 13:01:02 · 1 answers · asked by ricky884848 1 in Computers & Internet Programming & Design

1 answers

int c;
boolean lastWasLetter = false;
while ((c = System.in.read()) != -1) {
boolean curIsLetter = Character.isLetter((char) c);
if (lastWasLetter && ! curIsLetter) System.out.print("ay");
System.out.print((char) c);
lastWasLetter = curIsLetter;
}

===================

Sample input:
I love to eat food

Sample output:
Iay loveay toay eatay fooday

======================
Alternative implementation with regex:

import java.util.regex.*;

String s = "I like to eat food";
Pattern p = Pattern.compile( "([a-zA-z])\\b");
Matcher m = p.matcher(s);
System.out.println( m.replaceAll("$1ay"));

2007-07-09 13:25:51 · answer #1 · answered by McFate 7 · 0 0

fedest.com, questions and answers