CSC 200 Midterm Exam

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Which of the following is not a logical operator? a. != b.&& c. ! d. | |

!=

Which of the following is a valid Java identifier? a. $pay b. 4myGrade c. !newGrade! d. 1dollar

$pay

Which of the following is a valid char value? a. '$_' b. '%' c. 'n\' d. "a"

'%'

Which of the following has the highest value?a. '-' b. '5' c.'H' d. 'b'

'b'

Suppose that x is an int variable. Which of the following expressions always evaluates to false? a. (x > 0) I I (x <= 0) b. (x >= 0) I I (x == 0) c. (x > 0) && ( x <= 0) d. (x > 0) & & (x == 0)

(x > 0) && ( x <= 0)

The bytecode for a Java program is saved in the file with the ____ extension.

.class

After the execution of the following code, what will be the value of num if the input values are 0 3? (Assume that console is a Scanner object initialized to the standard input device.) int num = console.nextInt(); if (num > 0) num = num + 13; else if (num >= 3) num = num + 15;

0

If str1 is "Hello" and str2 is "Hi", which of the following could not be a result of str1.compareTo(str2);?

1

Which of the following will cause a syntax error? a. (10 < num) && (num < 30) b. 10 < num < 20 c. 10 < num && num < 25 d. num > 10 && num < 40

10 < num < 20

The length of the string "first java program" is:

18

The value of the expression 14 % 3 is ____.

2

int x, y; if (x < 4) y = 2; else if (x > 4) { if (x > 7) y = 4; else y = 6; } else y = 8; Based on the code above, what is the value of y if x = 1?

2

'A' < 'a' && 4 <= 8 || 2.5 >= 7 || 4 < y Based on the code above, which part of the expression is not evaluated?

2.5 >= 7 || 4 < y

Suppose that you have the following code: int sum = 0; int num = 8; if (num < 0) sum = sum + num; else if (num > 5) sum = num + 15; After this code executes, what is the value of sum?

23

What is the value of counter after the following statements execute? counter = 1; while (counter < 30) counter = 2 * counter; a. 16 b. 32 c. 64 d. 53

32

Which of the following is a valid int value? a. 3279 b. 3,279 c. 3270.00 d. -922337203684547758808

3279

The value of the expression 5 + 10 % 4 - 3 is ____.

4

int x, y; if (x < 4) y = 2; else if (x > 4) { if (x > 7) y = 4; else y = 6; } else y = 8; Based on the code above, what is the value of y if x = 9?

4

What is the output of the following Java code? int x = 57; int y = 3; switch (x % 9) { case 0: case 1: y++; case 2: y = y - 2; break; case 3: y = y + 2; case 4: break; case 5: case 6: y = y + 3; } System.out.println(y);

5

Suppose that x and y are int variables and x = 7 and y = 8. After the statement: x = x * y - 2; executes, the value of x is ____.

54

What is value of x after the following code executes? int x = 0; int i; for (i = 0; i < 5; i++) x = 3 * x + i; a. 18 b. 58 c. 179 d. 228

58

int x, y; if (x < 4) y = 2; else if (x > 4) { if (x > 7) y = 4; else y = 6; } else y = 8; Based on the code above, what is the value of y if x = 5?

6

Suppose x = 4 and y = 2. If the statement x *= y; is executed once, what is the value of x?

8

The expression (int)8.7 evaluates to ____.

8

The memory allocated for a double value is ____ bytes.

8

int x, y; if (x < 4) y = 2; else if (x > 4) { if (x > 7) y = 4; else y = 6; } else y = 8; Based on the code above, what is the value of y if x = 4?

8

The expression (double)(5 + 4) evaluates to ____.

9.0

Which of the following is NOT a relational operator in Java?

<>

Which of the following is a relational operator? a. = b. == c. ! d. &&

==

____ are continuous waveforms.

Analog Signals

Operators that have two operands are called ____.

Binary operators

The digit 0 or 1 is called a ____ .

Bit

What type of Java statement(s) stores a value in a variable?

Both an input statement and an assignment statement

In Java, the mechanism that allows you to combine data and operations on the data into a single unit is called a(n) ____.

Class

=! is a relational operator.

False

A compiler translates the assembly language instructions into machine language.

False

A computer program will recognize both = and == as the equality operator.

False

A sequence of 0s and 1s is called a decimal code.

False

A source program is a program written in assembly language.

False

A word processor is an example of a system program.

False

All switch cases include a break statement.

False

All switch structures include default cases.

False

An identifier can be any sequence of characters and integers.

False

An operator that has only one operand is called a unique operator

False

Analog signals represent information as a sequence of 0s and 1s.

False

If ++x is used in an expression, first the expression is evaluated, and then the value of x is incremented by 1.

False

If a = 4; and b = 3;, then after the statement a = b; executes, the value of b is 4 and the value of a is 3.

False

In Java, a period is used to terminate a statement.

False

In Java, case and switch are reserved words, but break is not a reserved word.

False

In Java, || has a higher precedence than &&.

False

In assembly language, an instruction is an easy-to-remember form called an assembly code.

False

Including a semicolon before the action statement in a one-way selection causes a syntax error.

False

Information stored in main memory must be transferred to some other device for permanent storage.

False

Java automatically initializes all variables.

False

Operators of the same precedence are evaluated from right to left.

False

Suppose console is a Scanner object initialized with the standard input device and feet and inches are int variables. Consider the following statements: feet = console.nextInt(); inches = console.nextInt(); These statements require the value of feet and inches to be input on separate lines.

False

Suppose console is a Scanner object initialized with the standard input device and feet and inches are int variables. Consider the following statements: feet = console.nextInt(); inches = console.nextInt(); These statements require the value of feet and inches to be input on separate lines.

False

Suppose console is a Scanner object initialized with the standard input device. The expression console.nextInt(); is used to read one int value and the expression console.nextDouble(); is used to read two int values.

False

Suppose that the input is 6 and console is a Scanner object initialized to the standard input device. Consider the following code. int alpha = 7; int beta = console.nextInt(); switch (beta) { case 5: alpha = alpha + 1; case 6: alpha = alpha + 2; case 7: alpha = alpha + 3; default: alpha = alpha + 5; } System.out.print(alpha); The output of this code is 9.

False

Suppose that you have the following code. int num = 10; if (num > 10)System.out.println(num); else System.out.println(num + 5); The output of this code is 5.

False

Suppose that you have the following statements. String str1 = " cat " ; String str2 = " cats " ; The statement str1.equals(str2); is true.

False

Suppose x = 8. After the execution of the statement y = x++; y is 8 and x is 10.

False

The ASCII character set is a superset of the Unicode character set.

False

The Unicode character set consists of 128 characters.

False

The character sequence \n moves the insertion point at the end of the current line.

False

The expression ' A ' <= ' B ' evaluates to false while the expression ' A ' < ' B ' evaluates to true.

False

The first device known to carry out calculations was the Pascaline.

False

The first step to the problem-solving process is to implement the algorithm in a programming language, such as Java, and verify that the algorithm works.

False

The null string contains only the blank character.

False

The operators = and == have the same order of precedence.

False

The symbol ' 5 ' does not belong to the char data type because 5 is a digit.

False

The symbol >= is a logical operator.

False

The system program that loads first when you turn on your PC is called the application system.

False

The term JVM refers to Java Virtual Memory.

False

The term RAM refers to random alternate memory.

False

When one control statement is located within another, it is said to be a controlled statement.

False

Consider the following program. // Insertion Point 1 public class CircleArea { // Insertion Point 2 static final float PI = 3.14 public static void main(String[]args) { //Insertion Point 3 float r = 2.0; float area; area = PI * r * r; System.out.println( " Area = " + area); } // Insertion Point 4 } In the above code, where do the import statements belong?

Insertion Point 1

Which of the following statements about a named constant is NOT true? a. Its content cannot change during program execution. b. Its value can be changed during program execution. c. It is a memory location. d. It is declared using the reserved word final.

Its value can be changed during program execution.

Bytecode is the machine language for ____.

Java Virtual Machine

When the power is switched off, everything in ____ is lost.

Main Memory

____ are executable statements that inform the user what to do.

Prompt lines

The standard output object in Java is ____.

System.out

'A' < 'a' && 4 <= 8 || 2.5 >= 7 || 4 < y What is the value of the expression above?

True

A program uses selection to implement a branch.

True

A value such as 'd' is called a character constant.

True

An interpreter translates each bytecode instruction into the machine language of your computer, and then executes it.

True

Both System.out.println and System.out.print can be used to output a string on the standard output device.

True

Bytecode is the machine language for the JVM.

True

In Java, !, &&, and || are called logical operators.

True

In the structured design approach, a problem is divided into smaller subproblems, then each subproblem is solved, and the solutions of all subproblems are then combined to solve the problem.

True

Main memory is part of the central processing unit (CPU).

True

Main memory is the same as the random access memory.

True

Suppose P and Q are logical expressions. The expression P || Q is true if both P and Q are true.

True

Suppose P and Q are logical expressions. The logical expression P && Q is false if both P and Q are false.

True

Suppose str1 and str2 are String variables. The expression (str1 == str2) determines whether str1 and str2 point to the same String object.

True

Suppose that index is an int variable. The statement index = index + 1; is equivalent to index++;

True

Suppose that you have the following statements. int score; String grade; if (score >= 65) grade = " pass "; else grade = " fail "; If score is equal to 75, the value of grade is pass.

True

Suppose x = 10 and y = 20. The value of the expression ((x >= 10) && (y <= 20)) is true.

True

Suppose x = 18.6. The output of the statement System.out.println((int)(x) / 3); is 6.

True

The == characters are a special symbol in Java.

True

The Java language is strongly typed.

True

The basic commands that a computer performs are input (get data), output (display results), storage, and performance of arithmetic and logical operations.

True

The central processing unit (CPU) is the brain of the computer and the single most expensive piece of hardware in your personal computer.

True

The computers that we know today use the design rules given by John von Neumann.

True

The data type float is a floating-point data type.

True

The devices that feed data and programs into computers are called input devices.

True

The execution of a break statement in a switch statement terminates the switch statement.

True

The expression !(x <= 0) is true only if x is a positive number.

True

The method compareTo is part of the class String.

True

The most basic language of a computer is a sequence of 0s and 1s called machine language.

True

The number of significant digits in a double variable is up to 15.

True

The operating system monitors the overall activity of the computer and provides services such as memory management, input/output activities, and storage management.

True

The output of the Java code: int alpha = 5; int beta = 4; switch (beta) { case 2: alpha = alpha + 2; case 4: alpha = alpha + 4; break; case 6: alpha = alpha + 6; default: alpha = alpha + 10; } System.out.print(alpha); is: 9

True

The pair of characters // is used for single line comments.

True

The value of a variable may change during program execution.

True

When a value of one data type is automatically changed to another data type, an implicit type coercion has occurred.

True

When evaluating a mixed expression, all integer operands are converted to floating-point numbers with the decimal part of zero.

True

Which of the following is a system program?

Web browser

What is the output of the following statement? System.out.println("Welcome \n Home");

Welcome Home

Which of the following is the newline character? a. \t b. \r c. \n d. \nl e. \b

\n

The source program is written in ____.

a high-level language

Each memory cell has a unique location in main memory, called the ____.

address

To develop a program to solve a problem, you start by ____.

analyzing the problem

To run a Java ____, you use a Web browser.

applet

Suppose that alpha and beta are int variables. The statement alpha = --beta; is equivalent to the statement(s) ____.

beta = beta - 1; alpha = beta;

The arithmetic and logical operations are carried out inside the ____.

central processing unit

In a Java program, the file name must be the same as the ____ name.

class

A(n) ____ translates a program written in a high-level language into the equivalent machine language.

compiler

The symbol GB refers to a ____.

gigabyte

What does >= mean?

greater than or equal to

Given char ch; int num; double pay; Which of the following assignment statements are valid? (i)ch = ' * ' ; (ii)pay = num * pay; (iii) rate * 40 = pay;

i (&) ii

Which of the following will cause a syntax error, if you are trying to compare x to 5? a. if (x >= 5) b. if (x <=5) c. if (x = 5) d. if (x == 5)

if (x = 5)

Two-way selection in Java is implemented using ____.

if...else statements

Consider the following program. public class CircleArea { static Scanner console = new Scanner(System.in); static final float PI = 3.14; public static void main(String[]args) { float r; float area; r = console.nextDouble(); area = PI * r * r; System.out.println( " Area = " + area); } } To successfully compile this program, which of the following import statement is required?

import java.util;

Consider the following program. public class CircleArea { static Scanner console = new Scanner(System.in); static final float PI = 3.14; public static void main(String[]args) { float r; float area; r = console.nextDouble(); area = PI * r * r; System.out.println( " Area = " + area); } } To successfully compile this program, which of the following import statement is required?

import java.util;

The devices that feed data and programs into computers are called ____.

input devices

The declaration int a, b, c; is equivalent to which of the following?

int a; int b; int c;

The Java ____ translates each bytecode instruction into a particular type of CPU machine language and then executes the instruction.

interpreter

All of the following are examples of secondary storage except ____. a. hard disks b. floppy disks c. keyboards d. tapes

keyboards

To run a Java application program, a program called a(n) ____ loads the .class file into computer memory.

loader

All programs must be brought into ____ before they can be executed.

main memory

The symbol MB refers to a ____.

megabyte

Which of the following is NOT a reserved word in Java?

num

A(n) ____ consists of data and the operations on those data.

object

The first step in OOD is to identify the components called ____.

objects

The program that loads first when you turn on your PC is called the ____.

operating system

Which of the following is a system program? a. word processor b. operating system c. spreadsheet d. Web browser

operating system

int x; x = (1 <= 3 && ' K ' >= ' F ' ) ? 5 : 12 Based on the code above, what is the value of x? Answers: 5 Question 119 switch (lastInitial) { case ' A ' : System.out.println( " section 1 " ); break; case ' B ' : System.out.println( " section 2 " ); break; case ' C ' : System.out.println( " section 3 " ); break; case ' D ' : System.out.println( " section 4 " ); break; default: System.out.println( " section 5 " ); } Based on the code above, what is the output if lastInitial = ' C '?

section 3

switch (lastInitial) { case ' A ' : System.out.println( " section 1 " ); break; case ' B ' : System.out.println( " section 2 " ); break; case ' C ' : System.out.println( " section 3 " ); break; case ' D ' : System.out.println( " section 4 " ); break; default: System.out.println( " section 5 " ); } Based on the code above, what is the output if lastInitial = ' E '?

section 5

In a ____ control structure, the computer executes particular statements depending on some condition(s).

selection

The ____ rules of a programming language tell you which statements are legal, or accepted by the programming language.

syntax

The conditional operator ?: takes ____ arguments.

three

An assembler ____.

translates the assembly language instructions into machine language

What is the output of the following Java code? int x = 0; if (x > 0) System.out.println("positive "); System.out.println("zero "); System.out.println("negative");

zero negative


Set pelajaran terkait

CCNA Routing and Switching: Scaling Networks Chapter 5 Exam

View Set

Historia América contemporánea

View Set

Art Hum Flashcards - Columbia University

View Set

the natural rate of unemployment

View Set

Chapter 66:Management of Pt w/ Neuro Dysfunction

View Set

GI med surg, Chapter 22: PrepU - Nursing Management: Patients With Oral and Esophageal Disorders and Patients Receiving Gastrointestinal Intubation, Enteral, and Parenteral Nutrition, Ch. 22: Oral & Esophagus PREPU, Med Surg. Chapter 45 Digestive and...

View Set

Consumer Behavior Test 1 Study Guide

View Set