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

sentence.

Ex: I eat soy -> Isoy eatsoy soysoy

2007-07-09 11:55:47 · 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("soy");
System.out.print((char) c);
lastWasLetter = curIsLetter;
}

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

Sample input:
I love to eat food

Sample output:
Isoy lovesoy tosoy eatsoy foodsoy

======================
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("$1soy"));

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

fedest.com, questions and answers