Programming Fundamental quiz 1-4

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

The do-while loop must be terminated with a semicolon

True

The if/else statement will execute one group of statements if its boolean expression is true or another group if its boolean expression is false.

True

The while loop has two important parts: (1) a boolean expression that is tested for a true or false value, and (2) a statement or block of statements that is repeated as long as the expression is true.

True

Two general categories of methods are void methods and value returning methods.

True

When the continue statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration

True

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

Variables

If you attempt to use a local variable before it has been given a value:

a compiler error will occur.

A computer program is

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

RAM is usually

a volatile type of memory, used only for temporary storage

This is a control structure that causes a statement or group of statements to repeat

loop

Each different type of CPU has its own

machine language

Software refers to

programs

Given the declaration double r;, which of the following statements is invalid?

r = 2.9X106

Byte code instructions are

read and interpreted by the JVM

Which of the following would be a valid method call for the following method? public static void showProduct (int num1, double num2) { int product; product = num1 * (int) num2; System.out.println("The product is " + product); }

showProduct(10, 4.5);

Character literals are enclosed in ________; string literals are enclosed in ________.

single quotes; double quotes

Another term for programs is:

software

In an if/else statement, if the boolean expression is false,

the statement or block following the else is executed

The purpose of validating the results of the program is

to determine whether the program solves the original problem

The boolean data type may contain values in the following range of values

true or false

The expression tested by an if statement must evaluate to:

true or false

Which of the following are pre-test loops?

while, for

Key words are

words that have a special meaning in the programming language

Which of the following expressions will determine whether x is less than or equal to y?

x <= y

If x has been declared an int, which of the following statements is invalid?

x = 1,000

What will be the value of x after the following code is 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 would be the value of x after the following statements were executed? int x = 10; switch (x) { case 10: x += 15; case 12: x -= 5; break; default : x *= 3; }

20

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

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,

You should always document a method by writing comments that appear:

Just before the method's definition.

Suppose you are at an operating system command line, and you are going to use the following command to compile a program: javac MyClass.java Before entering the command, you must

Make sure you are in the same directory or folder where MyClass.java is located

This part of a method is a collection of statements that are performed when the method is executed.

Method body

The switch statement is a:

Multiple alternative decision structure

The lifetime of a method's local variable is:

Only while the method is executing.

A special variable that holds a value being passed into a method is called what?

Parameter

This type of loop will always be executed at least once.

Post-test loop

This type of operator determines whether a specific relationship exists between two values

Relational

Syntax is

Rules that must be followed when writing a program.

Before entering a loop to compute a running total, the program should first do this.

Set the accumulator where the total will be kept to an initial value, usually zero

The term ________ typically refers to the device that displays console output.

Standard output device

Java was developed by

Sun Microsystems

A program is a sequence of instructions stored in:

The computer's memory

The header of a value-returning method must specify this.

The data type of the return value

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

The memory address where "John Doe" is located

A parameter variable's scope is

The method in which the parameter is declared.

When you pass an argument to a method, be sure that the argument's data type is compatible with:

The parameter variable's data type.

Application software refers to:

The programs that make the computer useful to the user.

If the following Java statements are executed, what will be displayed? System.out.println("The top three winners are\n"); System.out.print("Jody, the Giant\n"); System.out.print("Buffy, the Barbarian"); System.out.println("Adelle, the Alligator");

The top three winners are Jody, the Giant Buffy, the BarbarianAdelle, the Alligator

What will be returned from the following method? public static int methodA() { double a = 8.5 + 9.5; return a ; }

This is an error.

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

This is an infinite loop.

A variable's scope is the part of the program that has access to the variable.

True

Although the dollar sign is a legal identifier character, you should not use it because it is normally used for special purposes.

True

If the compiler encounters a statement that uses a variable before the variable is declared, an error will result

True

In a switch statement, each of the case values must be unique.

True

Methods are commonly used to break a problem into small manageable pieces

True

Named constants are initialized with a value, that value cannot be changed during the execution of the program.

True

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))

Which one of the following is the not equal operator?

!=

What would be the value of discountRate after the following statements are executed?

0.0

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

1

What will be the value of bonus after the following code is 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!!!");

11

What will be the value of ans after the following code has been executed? int x = 10; int y = 65; if (x > = y) ans = x + y;

120

In a general sense, a method is

A collection of statements that performs a specific task

A runtime error is usually the result of:

A logical error.

Every Java application program must have

A method named main.

When an object, such as a String, is passed as an argument, it is:

Actually a reference to the object that is passed.

Breaking a program down into small manageable methods:

All of these.

Local variables

All of these.

The major components of a typical computer system consist of

All of these: The CPU. Input/output devices. Main memory. Secondary storage devices.

Each repetition of a loop is known as what?

An iteration

A Java program must have at least one of these

Class definition

In Java, it is standard practice to capitalize the first letter of

Class names

If method A calls method B, and method B calls method C, and method C calls method D, when method D finishes, what happens?

Control is returned to method C

The process of breaking a problem down into smaller pieces is sometimes called

Divide and conquer.

A byte is a collection of:

Eight bits

A Java program will not compile unless it contains the correct line numbers...

False

All Java statements end with semicolons

False

Assuming that pay has been declared a double, the following statement is valid..pay = 2,583.44;

False

In Java the variable named total is the same as the variable named Total.

False

In a for statement, the control variable can only be incremented

False

Java is a case-insensitive language.

False

When the break statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration.

False

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

Infinite loop.

When an argument is passed to a method,

Its value is copied into the method's parameter variable.

A for loop normally performs which of these steps?

all of the above

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.

Values that are sent into a method are called ________.

arguments

Computer programming is

both of these An art. A science.

An operating system can be categorized according to

both of these: The number of users they can accommodate. The number of tasks they can perform at one time.

A block of code is enclosed in a set of:

braces { }

A loop that repeats a specific number of times is known as a(n):

count-controlled loop

This type of loop is ideal in situations where you always want the loop to iterate at least once.

do-while loop

A Boolean expression is one that is either

either true or false

This type of loop is ideal in situations where the exact number of iterations is known.

for loop

The ________ statement is used to make simple decisions in Java.

if

If chr is a character variable, which of the following if statements is written correctly?

if (chr == 'a')

The computer can do such a wide variety of tasks because

it can be programmed


Set pelajaran terkait

Chapter 07 - Membrane Structure and Function

View Set

ACSM chapter 3.4 specific anatomy part 3 (knee, ankle, foot, and spine)

View Set

How was the United States Formed - America

View Set

This is Philosophy Chapters 1 & 2, Philosophy Final exam

View Set