14a-section-1-solutions

14a-section-1-solutions - CS 106A Handout #14A July 2, 2009...

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

View Full Document Right Arrow Icon
Handout #14A CS 106A July 2, 2009 Solutions for Section #1 1. The Fibonacci sequence /* * File: Fibonacci.java * -------------------- * This program lists the terms in the Fibonacci sequence up to * a constant MAX_TERM_VALUE, which is the largest Fibonacci term * the program will display. */ import acm.program.*; public class Fibonacci extends ConsoleProgram { /* Defines the largest term to be displayed */ private static final int MAX_TERM_VALUE = 10000; public void run() { println("This program lists the Fibonacci sequence."); int t1 = 0; int t2 = 1; while (t1 <= MAX_TERM_VALUE) { println(t1); int t3 = t1 + t2; t1 = t2; t2 = t3; } } }
Background image of page 1

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

View Full DocumentRight Arrow Icon
– 2 – 2. Drawing a robot face /* * File: RobotFace.java * -------------------- * This program draws a robot face as described in the handout for * Section #2. */ import acm.graphics.*; import acm.program.*; import java.awt.*; public class RobotFace extends GraphicsProgram { /* Parameters for the drawing */ private static final int HEAD_WIDTH = 100; private static final int HEAD_HEIGHT = 150;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

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

Page1 / 3

14a-section-1-solutions - CS 106A Handout #14A July 2, 2009...

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

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