CS180 Midterm

Ace your homework & exams now with Quizwiz!

Which of the following is the correct boolean expression to test for: int x being a value between, but not including, 500 and 650, or int y not equal to 1000

((x > 500 && x < 650) || (y != 1000))

A Java source file must be saved with the extension

.java

What will be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 100; if (purchase > 1000) discountRate = 0.05; else if (purchase > 750) discountRate = 0.03; else if (purchase > 500) discountRate = 0.01;

0.0

What will be the value of discountRate after the following statements are executed? double discountRate; char custType = 'C'; switch (custType) { case 'A': discountRate = 0.08; break; case 'B': discountRate = 0.06; case 'C': discountRate = 0.04; default: discountRate = 0.0; }

0.0

What will be the value of discountRate after the following statements are executed? double discountRate; char custType = 'B'; switch (custType) { case 'A': discountRate = 0.08; break; case 'B': discountRate = 0.06; break; case 'C': discountRate = 0.04; break; default: discountRate = 0.0; }

0.06

How many times will the following do-while loop be executed? int x = 11; do { x += 20; } while (x > 100);

1

What will be the value of bonus after the following statements are executed? int bonus, sales = 10000; if (sales < 5000) bonus = 200; else if (sales < 7500) bonus = 500; else if (sales < 10000) bonus = 750; else if (sales < 20000) bonus = 1000; else bonus = 1250;

1000

How many times will the following for loop be executed? for (int count = 10; count <= 21; count++) System.out.println("Java is great!");

12

What does the following code display? double x = 12.3798146; System.out.printf("%.2f\n", x);

12.38

What will be the value of x after the following statements are executed? int x = 75; int y = 60; if (x > y) x = x - y;

15

What is the value of x after the following code has been executed? int x = 75; int y = 90; if (x != y) x += y;

165

What is the result of the following expression? 17 % 3

2

What will be the value of x after the following code is executed? int x, y = 4, z = 6; x = (y++) * (++z);

28

What is the result of the following expression? 20 / 6

3

What will be the value of x after the following statements are executed? int x = 10; for (int y = 5; y < 20; y +=5) x += y;

40

What is the value of pay after the following code executes? int hours = 45; double pay, payRate = 10.00; pay = hours <= 40 ? hours * payRate : 40 * payRate + (hours - 40) *payRate * 1.5;

475.0

How many times will the following do-while loop be executed? int x = 10; do { System.out.println("looping through..."); x += 20; } while (x < 100);

5

What is the result of the following expression? 10 + 5 * 3 - 20

5

What will be printed after the following code is executed? for (int number = 5; number <= 15; number +=3) System.out.print(number + ", ");

5, 8, 11, 14,

What will be the value of ans after the following statements are executed? int x = 40; int y = 40; if (x = y) ans = x + 10;

50

What is the result of the following expression? 17 % 3 * 2 - 12 + 15

7

There are __________ bits in a byte.

8

What is the value of z after the following statements have been executed? int x = 4, y = 33; double z; z = (double) (y / x);

8.0

What is the value of z after the following statements have been executed? int x = 4, y = 33; double z; z = (double) y / x;

8.25

What is the value of ans after the following code has been executed? int x = 35; int y = 20, ans = 80; if (x < y) ans += y;

80

The end of a Java statement is indicated by a ________.

; semicolon

Which of the following is a value that is written into the code of a program? a. assignment statement b. variable c. literal d operator

C

Which of the following is not one of the major components of a typical computer system? a. CPU b. Main memory c. operating System d. secondary storage devices

C

Which of these is NOT an input device? a. scanner b. webcam c. monitor d. stylus

C

Which of these is NOT an output device? a. monitor b. speaker c. printer d. keyboard

D

Which of the following files would contain the translated Java byte code for a program named Demo?

Demo.class

Which of the following statements opens a file named MyFile.txt and allows you to read data from it?

File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file);

Which of the following statements opens a file named MyFile.txt and allows you to append data to its existing contents?

FileWriter fwriter = new FileWriter("MyFile.txt", true);PrintWriter outFile = new PrintWriter(fwriter);

Which of the following statements will create an object from the Random class?

Random myNumber = new Random();

set up a random number

Random rand = new Random();

The boolean expression in an if statement must evaluate to

T/F

Software refers to

The programs that run on a computer

The boolean data type may contain which of the following range of values?

True/False

Key words are

Words that have a special meaning in the programming language (int, double)

a += b

a = a + b

Every Java application program must have

a method named main

In all but very rare cases, loops must contain ________________.

a way to terminate

The variable used to keep a running total in a loop is called a(n) __________.

accumulator

Which of the following is not part of the programming process? design/model, debugging/correcting errors, testing

all are parts of the process

What will be the values of ans, x, and y after the following statements are executed? int ans = 35, x = 50, y = 50; if (x >= y) { ans = x + 10; x -= y; } else { ans = y + 10; y += x; }

ans = 60, x = 0, y = 50

Because Java byte code is the same on all computers, compiled Java programs

are highly portable

A block of code is enclosed in a set of

braces {}

In the following code, what values could be read into number to terminate the while loop? Scanner keyboard = new Scanner(System.in); System.out.print("Enter a number: "); int number = keyboard.nextInt(); while (number < 100 && number > 500) { System.out.print("Enter another number: "); number = keyboard.nextInt(); }

can never be true

Which String class method returns a character from a specified location in a String?

charAt();

Which of the following expressions determines whether the char variable, grade, is not equal to the letter 'A'?

chrA != 'A'

RAM

computer's main memory, temporary/volatile

Variables are

created by the programmer as an identifier. the names represent a location in memory

Variables are classified according to their

data type

Given the following statement, which of the following expressions would be used to generate a value on a game die? Random randomNumbers = new Random();

die = rand.nextInt(6) + 1;

Given the following statement, which statement will write the string "Calvin" to the file DiskFile.txt? PrintWriter diskOut = new PrintWriter("DiskFile.txt");

diskOut.printIn("Calvin");

A __________ loop will always be executed at least once.

do while

%20f

double formatting

What would be displayed as a result of executing the following code? final int x = 22; int y = 4; x = x + y; System.out.println("x = " + x + ", y = " + y);

error

What would be printed out as a result of the following code? System.out.println("The quick brown fox" + "jumped over the \n" "slow moving hen.");

error

coin toss

for (int count = 0; count < 10; count++) { if (rand.nextInt(2) == 0) else ....

%5s

format string/words

__________ refers to the physical components that a computer is made of.

hardware

CPU (Central Processing Unit)

heart of the computer that fetches and follows instructions, then produces data. has two parts: ALU and control unit

Which of the following is NOT a rule that must be followed when naming identifiers?

identifiers can contain spaces

Which of the following statements determines whether the variable temp is within the range of 0 through 100 (inclusive)?

if (temp >= 0 && temp <= 100)

When working with the PrintWriter class, which of the following import statements should you have near the top of your program?

import java.util.*;

Which of the following statements correctly creates a Scanner object for keyboard input?

import java.util.*; Scanner keyboard = new Scanner(System.in);

If a loop does not contain, within itself, a valid way to terminate, it is called a(n) __________ loop.

infinite

Assuming that inputFile references a Scanner object that was used to open a file, which of the following statements will read an int from the file?

int number = inputFile.nextInt();

%3d

integer formatting

Each repetition of a loop is known as a(n)

iteration

Which of the following will run the compiled program called ReadIt?

java ReadIt

To compile a program named First you would use which of the following commands?

javac First.java

Which of the following will compile a program called ReadIt?

javac ReadIt.java

The variable that controls the number of times a loop iterates is known as a(n) __________.

loop control variable

For the following Java statement, what value is stored in the variable name? String name = "John Doe";

memory address where "John Doe" is located

Given the following statement, which of the following expressions will generate a random number in the range of 1 through 10? Random randomNumbers = new Random();

myNumber = randomNumbers.nextInt(10) +1;

Which Scanner class method reads a String?

next(); or nextLine();

!=

not equal to

What will be the value of x after the following code is executed? int x = 10, y = 20; while (y < 100) { x = x + y; }

nothing, infinite loop

In the following code, what values could be read into number to terminate the while loop? Scanner keyboard = new Scanner(System.in); System.out.print("Enter a number: "); int number = keyboard.nextInt(); while (number < 100 || number > 500) { System.out.print("Enter another number: "); number = keyboard.nextInt(); }

number > 100 and number < 500

A cross between human language and a programming language is called

pseudocode

Byte code instructions are

read and interpreted by the JVM and cannot be directly executed by the CPU

A(n) __________ is a special value that cannot be mistaken as a member of a list of data items and signals that there are no more data items to be processed.

sentinel

a computer program is

set of instructions that directs the computer to perform a task or solve a problem

Character literals are enclosed in __________ and string literals are enclosed in __________.

single quotes; double quotes

If str1 and str2 are both String objects, which of the following expressions will correctly determine whether or not they are equal?

str1.equals(str2)

Which of the following expressions could be used to perform a case-insensitive comparison of two String objects named str1 and str2?

str1.equalsIgnoreCase(str2)

What is syntax?

strict rules in programming languages

Which of the following is NOT a primitive data type? byte, short, int, long, float, double, boolean, char, string

string

Which of the following is the method you can use to determine whether a file exists?

the File class's exists method

running total

total = total + variable

line break

use printf "\n"

The __________ loop allows the user to decide on the number of iterations.

user controlled loops

Which of the following is a named storage location in the computer's memory?

variable

In Java, __________ must be declared before they can be used.

variables

Assume that inputFile references a Scanner object that was used to open a file. Which of the following while loops is the correct way to read data from the file until the end of the file is reached?

while (inputFile.hasNext())

Which of the following are pre-test loops?

while, for

Which of the following statements will correctly convert the data type, if x is a float and y is a double?

x = (float)y;

What output will be displayed as a result of executing the following code? int x = 5, y = 20; x += 32; y /= 4; System.out.println("x = " + x + ", y = " + y);

x = 37, y = 5

What will be the values of x and y as a result of the following code? int x = 25, y = 8; x = y++;

x = 8, y = 9


Related study sets

Exam #2 (Chp 6-10) - Organizational Behavior

View Set

Maslow's hierarchy of needs (needs based theory)

View Set

6013 Security in Mobile Computing Final

View Set