36a-practice-final-solutions

# 36a-practice-final-solutions - Handout#36A CS 106A Answers...

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

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.

Unformatted text preview: Handout #36A CS 106A Aug 13, 2008 Answers to Practice Final Problem 1—Short answer (11 points) 1a) The answer is feli 1b) private char ch; public void run() { ch = 'e'; String word = "bookkeeper"; String soFar = "b--kk--p--"; String answer = revealLetter(word, soFar); ch = 'f'; println(“Guessing e on “ + soFar + “ gives us: “ + answer); } private String revealLetter(String word, String display) { String nuWord; for(int i = 1; i < word.length(); i++) { char ch = word.charAt(i); if(ch.equals(this.ch)) { nuWord += this.ch; }else{ nuWord += display; } } return nuWord; } } – 2 – Problem 2 – Arrays (19 points) //Solution for problem 2a private String odometerString( int array) { String s = "" ; int i = 0; //advances the cursors so that we skip any leading zeroes while (array[i] == 0) { i++; if (i == 5) { break ; } } //goes through and copies the numbers into the string //inserting commas n stuff. while (i < array. length ) { s+=array[i]; if (i == 2) { s+= "," ; } if (i == 5) { s+= "." ; } i++; } return s; } //Solution for problem 2b private void add1TenthMile( int digits) { int i = 6; digits[i]++; while (digits[i] >= 10 && i > 0) { digits[i] = 0; i--; digits[i]++; } if (digits[0] >= 10) { digits[0] = 0; } } – 3 –...
View Full Document

{[ snackBarMessage ]}

### Page1 / 6

36a-practice-final-solutions - Handout#36A CS 106A Answers...

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

View Full Document
Ask a homework question - tutors are online