Tags

, , ,

Course: Berkeley’s CS 61B: Data Structures.

Homework 1

Homework 1 (mirror) is due before Lecture 4.

Two introductory problems about String manipulations.

Problem 1
———
Write a program that reads a String from the keyboard. The program should then construct a URL for http://www.X.com/, replacing X with the String read in, and print the first five lines of the Web page at that URL in REVERSE ORDER; i.e., the fifth, fourth, third, second, and first lines.

OpenCommercial.java (view | download)

Problem 2
———
Write a program called “Nuke2.java” containing a class called Nuke2 whose main method reads a string from the keyboard and prints the same string, with its second character removed. (That’s character number 1, since Java numbers characters in a string starting from zero.) In other words, after you run “java Nuke2”, if you type in the string “skin”, the program will print “sin”.

Nuke2.java (view | download)

Advertisements