{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

27S-Section-Solution

# 27S-Section-Solution - CS106A Handout 27S May 4th 6th 2011...

This preview shows pages 1–2. Sign up to view the full content.

CS106A Handout 27S Spring 2011 May 4 th – 6 th , 2011 Section Solution Discussion Problem 1 Solution: Adding commas to numeric String s private String addCommasToNumericString(String digits) { String result = ""; int len = digits.length(); int nDigits = 0; for ( int i = len - 1; i >= 0; i--) { result = digits.charAt(i) + result; nDigits++; if (nDigits % 3 == 0 && i > 0) { result = "," + result; } } return result; } Discussion Problem 2 Solution: Double Speak private String doubleSpeak(String original) { String transformed = ""; String vowelCluster = ""; for ( int i = 0; i < original.length(); i++) { char ch = original.charAt(i); boolean isVowel = isVowel(ch); if (isVowel) { vowelCluster += ch; } else if (vowelCluster.length() > 0) { transformed += "bb" + vowelCluster; vowelCluster = ""; } transformed += ch; } if (vowelCluster.length() > 0) { transformed += "bb" + vowelCluster; vowelCluster = ""; } return transformed; } private boolean isVowel(char ch) { switch (ch) { case 'a': case 'e': case 'i': case 'o': case 'u': return true; default : return false ; } }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 2

27S-Section-Solution - CS106A Handout 27S May 4th 6th 2011...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online