24-section-4

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

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Mehran Sahami Handout #24 CS 106A October 19, 2009 Section Handout #4: String Processing Portions of this handout by Eric Roberts and Patrick Young 1. Adding commas to numeric strings (Chapter 8, Exercise 13, page 290) When large numbers are written out on paper, it is traditional at least in the United States to use commas to separate the digits into groups of three. For example, the number one million is usually written in the following form: 1,000,000 To make it easier for programmers to display numbers in this fashion, implement a method private String addCommasToNumericString(String digits) that takes a string of decimal digits representing a number and returns the string formed by inserting commas at every third position, starting on the right. For example, if you were to execute the main program public void run() { while (true) { String digits = readLine("Enter a numeric string: "); if (digits.length() == 0) break; println(addCommasToNumericString(digits)); } } your implementation of the addCommasToNumericString method should be able to produce the following sample run:...
View Full Document

This note was uploaded on 12/01/2009 for the course CS 106A taught by Professor Sahami,m during the Fall '08 term at Stanford.

Page1 / 3

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online