CS 1400 MIDTERM EXAM QUESTIONS WITH VERIFIED
ANSWERS
What does the combination of a double and an integer get you? - Answers - A decimal
What is the output of the following code segment?
System.out.println( (double) () ); - Answers - 2.0
What is the result of the Modulus Division?
System.out.println( 11 % 4 ) - Answers - 3
What is the output of the following code segment?
System.out.println(1 + 2 + "abc" + 3 + 4); - Answers - 3abc34
What is the code called that is written in English and is used to help you work out the
logic in an algorithm? - Answers - Pseudocode
Which is the best name for a variable in camel case that will store a person's first
name? - Answers - firstName
What is the best data type for a variable that will store a street name - Answers - String
What is the output of the following code segment?
System.out.println(3 + 4 % 3); - Answers - 4
What type of programming error will allow your program to run, but give incorrect
output? - Answers - Logic Error
What is the correct syntax for a single line comment? - Answers - //
What is the correct syntax for a Multi-line comment in Java? - Answers - /* */
What is the result of the Floating Point Division?
System.out.println( 11. ); - Answers - 2.75
What type of code are you writing when you are coding in Java? - Answers - Source
Code
What is the result of the Integer Division?
System.out.println( ) - Answers - 2
What is the best name for a variable to store the number of computers in a room? -
Answers - numComputers
, What is the best data type to store the number of computers in a room? - Answers - int
Which would correctly read a value an int value from the keyboard given the following
Scanner?
Scanner keyboard = new Scanner(System.in); - Answers - int num = keyboard.nextInt();
Which would correctly read the entire line of text from the keyboard given the following
Scanner?
Scanner keyboard = new Scanner(System.in); - Answers - String line =
keyboard.nextLine();
What is the purpose of the following line of code?
Scanner keyboard = new Scanner(System.in); - Answers - Creates an object that will
allow you to read in from the keyboard
What is the best data type to store the state of a light bulb (on or off)? - Answers -
boolean
What would be displayed by the following code segment?
int num = 5;
num += 3;
System.out.println(num); - Answers - 8
What is the best data type to represent PI or 3.14159? - Answers - double/float
What is the best data type to store a persons' street address? - Answers - String
The following code segment is shown both with an IF structure and an IF Else structure.
What is the final output of num in both situations?
(If Series)
int num = 0;
int test = 7;
if(test == 7){num++;}
if(test > 0) {num++;}
(If Else Structure)
int num = 0;
int test = 7;
if(test == 7){num++;}
else if(test > 0) {num++;} - Answers - If Series: 2
If Else Structure: 1
What is the difference between = and == in Java? - Answers - = is to assign a value, ==
is to compare
ANSWERS
What does the combination of a double and an integer get you? - Answers - A decimal
What is the output of the following code segment?
System.out.println( (double) () ); - Answers - 2.0
What is the result of the Modulus Division?
System.out.println( 11 % 4 ) - Answers - 3
What is the output of the following code segment?
System.out.println(1 + 2 + "abc" + 3 + 4); - Answers - 3abc34
What is the code called that is written in English and is used to help you work out the
logic in an algorithm? - Answers - Pseudocode
Which is the best name for a variable in camel case that will store a person's first
name? - Answers - firstName
What is the best data type for a variable that will store a street name - Answers - String
What is the output of the following code segment?
System.out.println(3 + 4 % 3); - Answers - 4
What type of programming error will allow your program to run, but give incorrect
output? - Answers - Logic Error
What is the correct syntax for a single line comment? - Answers - //
What is the correct syntax for a Multi-line comment in Java? - Answers - /* */
What is the result of the Floating Point Division?
System.out.println( 11. ); - Answers - 2.75
What type of code are you writing when you are coding in Java? - Answers - Source
Code
What is the result of the Integer Division?
System.out.println( ) - Answers - 2
What is the best name for a variable to store the number of computers in a room? -
Answers - numComputers
, What is the best data type to store the number of computers in a room? - Answers - int
Which would correctly read a value an int value from the keyboard given the following
Scanner?
Scanner keyboard = new Scanner(System.in); - Answers - int num = keyboard.nextInt();
Which would correctly read the entire line of text from the keyboard given the following
Scanner?
Scanner keyboard = new Scanner(System.in); - Answers - String line =
keyboard.nextLine();
What is the purpose of the following line of code?
Scanner keyboard = new Scanner(System.in); - Answers - Creates an object that will
allow you to read in from the keyboard
What is the best data type to store the state of a light bulb (on or off)? - Answers -
boolean
What would be displayed by the following code segment?
int num = 5;
num += 3;
System.out.println(num); - Answers - 8
What is the best data type to represent PI or 3.14159? - Answers - double/float
What is the best data type to store a persons' street address? - Answers - String
The following code segment is shown both with an IF structure and an IF Else structure.
What is the final output of num in both situations?
(If Series)
int num = 0;
int test = 7;
if(test == 7){num++;}
if(test > 0) {num++;}
(If Else Structure)
int num = 0;
int test = 7;
if(test == 7){num++;}
else if(test > 0) {num++;} - Answers - If Series: 2
If Else Structure: 1
What is the difference between = and == in Java? - Answers - = is to assign a value, ==
is to compare