Java

INDEPENDENT TOPIC 05 – TIMING

 

LESSON WORK

 

 

QUESTION 1


Use the first timing approach discussed in the lesson to time how long the following statements (or code sections) take.  Remember that running the program several times will likely yield different answers.

 

a) int x = 5;

b) double z = -3;

c) int coco = 3;
if (coco > 1)
{
   coco = 2;

}

 

d) for (int z = 1; z < 100; z++)
{
     int y = 10;
}

 

e) System.out.println("hello world");

 

Any surprises?  Try different statements to see what you get.

QUESTION 2

Use the second time approach discussed in the lesson to time how long it takes for a person to type in their name and hit <Enter>.  Output the amount of milliseconds on the screen.