CS 0401 Quiz Study Guide
For Quiz 1 study all materials up to and including the lecture on Thursday, September 29, 2011 (Lecture 10).
The Quiz will be made up of 5 types of questions. Below is a description of each type and an example question (or 2).
Fill in the Blanks:
Provide the most appropriate answers (2 points each).
Ex:
Java ____keywords__________ are lexical elements (or identifiers) that have a special, predefined meaning, and they cannot be used in any other way.
The ___precedence__________ of Java operators indicates the order in which they are applied.
True / False: Explain
False statements for full credit (2 points each)
Ex:
Java logical
operators are used to compare 2 primitive values. False – logical operators are
used with boolean values – relational operators
are used to compare primitive values.
Java reference types store references to (or addresses of)
objects. True
Short Answers: Define / compare / explain / justify or
otherwise elaborate on the statements shown.
Ex:
Explain what is
wrong with the following Java code segment:
// Assume all vars are declared and init correctly
if (X > MAX)
System.out.println("New Max found");
MAX
= X;
System.out.println("MAX
is " + MAX);
The above is a logic error. The statement
MAX = X;
will
be executed regardless of the outcome of the test. This is because the syntax for the if
statement specifies only a single statement for the if clause.
Trace: Give all output produced by the execution of a given
Java program, in the correct order.
Ex:
See class handouts
Coding: Write Java
code as instructed in the problem.
Ex: Write a complete Java program that does the following:
Instructs the user to enter an integer between 1 and 10 (inclusive), then reads in an int and outputs it to the screen. A Scanner should be used for the input. If the value entered is outside the stated range, it should be rejected and the user should re-enter until the value is in the correct range.
import java.util.Scanner;
public class Code1
{
public
static void main(String [] args)
{
Scanner
inScan = new Scanner(System.in);
int
value;
do
{
System.out.print("Enter
a value between 1 and 10: ");
value
= inScan.nextInt();
}
while
(value < 1 || value > 10);
System.out.println("You
entered " + value);
}
}