☰ Contents Programs and Values

Programs and Values in Summary

Prof: OK, so what kinds of values have we seen so far?
Student: Well there’s int for exact numbers, String for text, and double for approximate decimal numbers.
Prof: Any others?
Student: Oh right! Pict for images! That was cool. Hey! You got me hooked with the whole “images are a cool thing you haven’t seen before” and then you went into the standard introduction to Java.
Prof: Oops, I guess I did. Did you at least feel like you learned something?
Student: Yeah, but I’m eager to do more!
Prof: Great!

Practice

Fill in the type of each definition so the program runs.
radius = 25;
label = "Radius: " + radius;
half = 12.5;
dot = new Circle(radius, "red");
Exactly one of these definitions runs without an error. Which one?
  1. string name = "Val";
    The type is spelled String, with a capital S.
  2. int count = "5";
    "5" is a string. An int definition needs a number without quotes, like 5.
  3. int total = 7 / 2;
  4. Pict p = new Circle("10", "red");
    Circle takes an int radius. "10" is a String, even though it looks like a number.

After this program runs, what does the book print for c?

int a = 17;
int b = a / 5;
int c = a - b * 5;