Unit 2 -- Csc 115 Spring 2005 SO1/S02


Learning Objectives

Continued review of Csc 110 material:

Learning Resources

Lecture slides: 2-IntroToJava.ppt
Reading: Chapter 1 in the textbook

Sample programs

Self-Study Activities

Answer the following questions:
  1. Experiment with the following code (if using Gild, explore the Dr.Java Interactions pane) and make sure you understand the output:
    int [] a;
    a = new int[5];
    a[0] = 42;
    a[0]
    a[1]
    a[5]
    a.length

    String[] answers = {“yes”, “no”};
    answers[0]
    answers.length
    int [] b = {12, -15, 42, 12, 10};
    b[5] = 11;
  2. What is the difference between a while statement and a do while statement?
  3. How can you translate a for loop into a while loop? Show how with an example and check it works in the Interactions Pane.
  4. Why is a String not an array of characters?
  5. Explain how we can simulate "pass by value" in Java.
Try playing with the following code in your code editor and make sure you understand the output and explain the results:
	int i = 3;
	double d = 3.2; 
	double dresult;
	dresult = i/d    // if displaying in the interaction pane, skip the semicolon to view the output
Now try this example... what happens and why doesn't it work?
	int i = 3;
	double d = 3.2;	
	int iresult; 
	iresult = i/d;   // there is a problem here, why?  

Problems in the textbook, Chapter 1:

See the following problems in the book:


Go to the course website