Java Programming Final Exam Review

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Valid code

/* * Author: Michelangelo * Date: 2014 * Address: 111 Main St, Pacific Ocean */ Valid Invalid

Invalid code

/* numKids = 2; /* Typical number */ numCars = 5; */

Valid code

/* numKids = 2; // Typical number numCars = 5; */

Valid code

// numKids = 2; // Typical number

True

A bit can only have the value of 0 or 1.

compile After finding the first error, the programmer should compile. Examining other errors often wastes time, since those may have stemmed from the first.

A compiler generates the following error messages: Line 7: Missing semicolon Line 9: numItems not defined Line 10: Expected '(' If the programmer corrects an error on line 7, the programmer should _____.

7 The first error message refers to line 7. The programmer should focus on the first error message

A compiler generates the following error messages: Line 7: Missing semicolon Line 9: numItems not defined Line 10: Expected '(' The programmer should start by examining line _____.

6 Sometimes a compiler doesn't notice an error exists until getting confused on a later line. Thus, the programmer should check the previous line, and if an error isn't found there, check even earlier lines.

A compiler generates the following error messages:Line 7: Missing semicolonLine 9: numItems not definedLine 10: Expected '(' If the programmer does NOT find an error on line 7, the programmer should check line _____.

False

A compiler warning by default will prevent a program from being created.

False

A compiler's default settings cause most warnings to be reported during compilation.

True

A memory stores bits.

following good practice Though beginning programmers may think such an approach wastes time, in fact the approach saves time. The approach enables faster detection and correction of errors. If multiple errors exist in large code, the errors may interact and be harder to detect and correct.

A new programmer writes 5 lines of code, compiles and runs, writes 5 more lines, and compiles and runs again. The programmer is _____

True

A processor executes instructions like, Add 200, #9, 201, represented as 0s and 1s.

programming dangerously Even experienced programmers tend to compile and run frequently. Errors are common, even for experienced programmers. 80 lines is probably dangerous, since errors may lurk in the code and be hard to find and correct.

An experienced programmer writes 80 lines of code, and then compiles and runs. The programmer is probably _____ .

numCars = scnr.nextInt();

Assuming scnr already exists, which statement gets an input number into variable numCars?

30

Consider the instruction: z = x + y. If x is 10 and y is 20, then z is assigned with _____.

the screen

Each System.out.print() and System.out.println() statements output items to _____.

Semicolon;

Each statement ends with what symbol?

No Error Some might think // creates a problem, but the compiler does not treat // as a comment when within a string literal.

Find the syntax errors. Assume variable numDogs has been declared. System.out.print("Amy // Michael");

Error Missing + before numDogs

Find the syntax errors. Assume variable numDogs has been declared. System.out.print("Dogs: " numDogs);

Error Missing the ending ", as in: System.out.print("Hello friends!");

Find the syntax errors. Assume variable numDogs has been declared. System.out.print("Hello friends!);

Error The declared variable was numDogs, not NumDogs. The compiler will report that NumDogs has not been declared.

Find the syntax errors. Assume variable numDogs has been declared. System.out.print(NumDogs);

Error Statements end with a semicolon, not period.

Find the syntax errors. Assume variable numDogs has been declared. System.out.print(numDogs).

Error Should be System.out.print, not System.print.

Find the syntax errors. Assume variable numDogs has been declared. System.print(numDogs);

Error Missing a semicolon after int numCats.

Find the syntax errors. Assume variable numDogs has been declared. int numCats numCats = 3; System.out.print(numCats);

Error Should be an uppercase S in System.

Find the syntax errors. Assume variable numDogs has been declared. system.out.print("Everyone wins.");

True

Generally, a programmer should not ignore warnings.

System.out.print (numCars);

Given variable numCars = 9, which statement outputs 9?

3 The compiler ignores the 2 blank lines and the line that only contains a comment.

How many lines of code will the compiler ignore in the code below? int userAge; int currentDecade; int nextDecade; int nextMilestone; // FIXME: Get user age userAge = 29; // Testing with 29 currentDecade = userAge / 10; nextDecade = currentDecade + 1; nextMilestone = nextDecade * 10;

6 The spaces before and after the =, -, and + are ignored by the compiler.

How many spaces will the compiler ignore in the code below? numToBuy = numNeeded - numInStock + 2;

False

If a compiler generates a specific message like "missing semicolon", then a semicolon must be missing somewhere, though maybe from an earlier line.

False

If a compiler says that an error exists on line 90, the actual error may be on line 91, 92, etc.

1978

In what year was the first C book published?

1985

In what year was the first C++ book published?

You're 22 years.

Indicate the actual output of each statement. Assume userAge is 22. System.out.print("You're " + userAge + " years.");

22years is good

Indicate the actual output of each statement. Assume userAge is 22. System.out.print(userAge + "years is good.");

Valid

Indicate which are valid code /* Determine width and height, calculate volume, and return volume squared. */

Valid

Indicate which are valid code /* Get user input */

Invalid

Indicate which are valid code // Print "Hello" Then print "Goodbye" And finally return. //

Valid

Indicate which are valid code // Print "Hello" to the screen //

Valid

Indicate which are valid code. // Get user input

Valid

Indicate which assignments are valid x = 1

{}

Program execution begins at main() and executes statements surrounded by which symbols?

False

Spaces are always ignored by the compiler.

8

Suppose a new instruction was inserted as follows:...z = x + y Add 1 more to z (new instruction)Put z to output What would the last instruction then output to the screen?

False

Switches have gotten larger over the years.

True

The computer inside a modern smartphone would have been huge 30 years ago.

40000 The variable wage holds 20, so wage * 40 * 50 will calculate 20 * 40 * 50, which is 40000. Note that the symbol for multiplication is * (an asterisk).

The expression wage * 40 * 50 resulted in what value?

hold

The statement int wage; creates a variable named wage that is used to _____ the value 20.

numUsers = scnr.nextInt();

Type a statement that gets an input value into variable numUsers. Assume scnr already exists and numUsers has been declared.

System.out.println("Hello");

Type a statement that outputs Hello and then starts a new output line.

System.out.print(numUsers); or System.out.println(numUsers);

Type a statement that outputs the value of numUsers (a variable). End statement with a semicolon.

System.out.print("Hello");

Type a statement that outputs: Hello

False

When a compiler says that an error exists on line 5, that line must have an error.

1995

When was the first public release of Java?

Multiply x by 1/2

Which instruction completes the program to compute a triangle's area? base = Get next input height = Get next input Assign x with base * height

a = ( x+y+z) /3

Which instruction completes the program to compute the average of three numbers? x = Get next input y = Get next input z = Get next input_____Put a to output

System.out.println("Hey");

Which statement outputs Hey followed by a new line?

System.out.print("Welcome!");

Which statement outputs: Welcome!

Invalid

x + 1 = 3

Invalid

x + y = y + x

Valid

x = y

Valid

x = y + 2


Ensembles d'études connexes

Managerial Accounting Test 1 Chapter 4

View Set

Latin American Government & Politics Final Exam 2016 (II)

View Set

NCLEX PASSPOINT NUR 221 Basic Care and Comfort

View Set

Art Appreciation Unit 5 (chapter 17, 18, 19 , 20)

View Set

CRIJ 2391 25- Intro to Criminal Justice Ch 3 book

View Set

D080 Managing in a Global Business Environment

View Set