Chapter 3 Flashcards

1
Q

What is an algorithm?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Explain briefly what is meant by “pseudocode” and how is it useful in the development of algorithms.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a block statement? How are block statements used in Java programs?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the main difference between a while loop and a do..while loop?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does it mean to prime a loop?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain what is meant by an animation and how a computer displays an animation.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Write a for loop that will print out all the multiples of 3 from 3 to 36, that is: 3 6 9 12 15 18 21 24 27 30 33 36.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Fill in the following main() routine so that it will ask the user to enter an integer, read the user’s response, and tell the user whether the number entered is even or odd. (You can use TextIO.getInt() to read the integer. Recall that an integer n is even if n % 2 == 0.)

public static void main(String[] args) {

     // Fill in the body of this subroutine!

}

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Write a code segment that will print out two different random integers selected from the range 1 to 10. All possible outputs should have the same probability. Hint: You can easily select two random numbers, but you have to account for the fact that the two numbers that you pick might be the same.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Suppose that s1 and s2 are variables of type String, whose values are expected to be string representations of values of type int. Write a code segment that will compute and print the integer sum of those values, or will print an error message if the values cannot successfully be converted into integers. (Use a try..catch statement.)

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Show the exact output that would be produced by the following main() routine:

public static void main(String[] args) {
    int N;
    N = 1;
    while (N <= 32) {
       N = 2 * N;
       System.out.println(N);   
    }
}
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Show the exact output produced by the following main() routine:

public static void main(String[] args) {
   int x,y;
   x = 5;
   y = 1;
   while (x > 0) {
      x = x - 1;
      y = y * x;
      System.out.println(y);
   }
}
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What output is produced by the following program segment? Why? (Recall that name.charAt(i) is the i-th character in the string, name.)

String name;
int i;
boolean startWord;

name = "Richard M. Nixon";
startWord = true;
for (i = 0; i < name.length(); i++) {
   if (startWord)
      System.out.println(name.charAt(i));
   if (name.charAt(i) == ' ')
      startWord = true;
   else
      startWord = false;
}
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Suppose that numbers is an array of type int[]. Write a code segment that will count and output the number of times that the number 42 occurs in the array.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Define the range of an array of numbers to be the maximum value in the array minus the minimum value. Suppose that raceTimes is an array of type double[]. Write a code segment that will find and print the range of raceTimes.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly