{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

24a-section-4-solutions

24a-section-4-solutions - Mehran Sahami CS 106A Handout#24A...

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

View Full Document Right Arrow Icon
Mehran Sahami Handout #24A CS 106A October 20, 2010 Solution to Section #4 Portions of this handout by Eric Roberts and Patrick Young 1. Adding commas to numeric strings 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; } 2. Deleting characters from a string private String removeAllOccurrences(String str, char ch) { String result = ""; for (int i = 0; i < str.length(); i++) {
Background image of page 1

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

View Full Document Right Arrow Icon