Homework 2: Programming warmup
2013-01-22
Feb 4, 11:59PM (note: updated due date)
Send an email to me at
jal2016@email.vccs.edu with
subject CSC 201 HW2 with your answers attached in a zip file.
Alternately, if you follow the directions for
185 HW3, you can put your assignment in a
folder named homework/201/hw2
in your repository, and email me
when you're done.
- Write a program in a class called
Squares
that prints all
the squares (1, 4, 9, 16, …) that are less than 1000.
- Write a program in a class called
Caps
that reads a single
line of text and prints it with each word capitalized. For example, if you
input hello there then it will print Hello There. Here's a
template to start with:
import java.util.Scanner;
public class Caps {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String line = input.nextLine();
// Print each word capitalized...
}
}
Hint: one way to do this is to loop over each character, and test to see
when you're at the start of a word. If you're operating on
char
data, the static method
Character.toUpperCase
can convert to upper case.
-
Write a program in a class called Calc
that works as a
simple calculator. Your calculator should accept at least 2 different
operations (e.g. addition and multiplication).
You can assume that each line looks like 500 + 33 or
32 * 11, or whatever format you prefer, but make sure
to specify your assumptions.
Add at least one extra feature. For example, you could save the
last output in a "variable" for the user to use in their expressions.
So if the users types 3 + 5 and then x + 3, x would
be treated as 8.