Programming Problem Solving I lect.

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

What is the output of the following code? int u = 3; int v = 5; u += v; v += u; u -= v; v -= u; PRINT (u + ", " + v);

-5, 18

What will this code print? int y=1; int x=1; PRINTLINE(x++);

1

What is the value of j after this code is executed? int i=6, int j=10; j+=i;

16

What is the output of the following code? int num1 = 500; int num2 = 200; int num3 = 300; double average = num1 + num2 + num3 / 3; PRINTLINE(average);

800.0

IDE stands for A) Integrated Development Environment B) Initial Degree Expectations C) Intramural Department Executive

A) Integrated Development Environment

Applying which term to a method allows the method to be called without creating an instance of the class it is in: A) Static B) Public C) Private D) Scope

A) Static

Consider variable x which is an int where x = 0, which statement below will be true after the following loop terminates? while (x < 100){ x *= 2; } A) The loop won't terminate. It's an infinite loop. B) x == 98 C) x == 0 D) x == 2

A) The loop won't terminate. It's an infinite loop.

What would be the best datatype to represent productItem? A variable that stores information about the number of items currently in stock in a grocery store. A) int B) String C) float D) double

A) int

Which of the following correctly refers to the last element in the array of integers called numbers? A) numbers[length of numbers-1] B) numbers[size] C) numbers[length of numbers] D) numbers[last numbers]

A) numbers[length of numbers-1]

Debugging is the process of A) solving errors in the source code. B) writing source code. C) publishing the source code to the client. D) compiling the source code.

A) solving errors in the source code.

This statement skips an iteration of a loop: A) NEXT B) CONTINUE C) SKIP D) BREAK

B) CONTINUE

An object's state refers to: A) Its set of methods B) Its set of data fields with the current values C) Its skeleton D) Its constructor's parameters

B) Its set of data fields with the current values

Pseudocode is A) a machine. B) an informal high-level description of the operating principle of a computer program or algorithm. C) a formal programming language.

B) an informal high-level description of the operating principle of a computer program or algorithm.

The Boolean expression ((A and B) and (not(A and B)) evaluates to: A) true whenever only A is true or only B is true. B) false in all cases. C) true in all cases. D) true whenever both A is true and B is true.

B) false in all cases.

Consider an array values. The array is of size 7. The statement: System.out.println(values[7]);//Java Console.WriteLine(values[7]);//C# cout << values[7] << endl;//C++ will A) output 7. B) produce an error. C) output 0. D) produce a syntax error.

B) produce an error.

Program design consists of A) writing the code for a program. B) steps a programmer should do before they start coding a program in a specific language. C) writing the documentation for a program. D) the ability to solve problems.

B) steps a programmer should do before they start coding a program in a specific language.

Infinite loops that have no terminating condition A) Cause an overflow error B) Cause an underflow error C) Appear to lock up D) None of these

C) Appear to lock up

Consider the array declaration and instantiation: int[ ] arrayOne = new int[5]; Which of the following is true about arrayOne? A) It stores 4 elements with legal indices from 1 to 4. B) It stores 6 elements with legal indices from 0 to 5. C) It stores 5 elements with legal indices from 0 to 4. D) It stores 5 elements with legal indices from 1 to 5.

C) It stores 5 elements with legal indices from 0 to 4.

Creating multiple methods (or constructors) with the same name but different parameters (number of parameters and/or data type of parameters and/or order of parameters) is called: A) Overriding B) Objections C) Overloading D) Overwriting

C) Overloading

Which of these is not a type of loop? A) FOR B) DO...WHILE C) WHILE...DO D) WHILE

C) WHILE...DO

Programming starts with A) writing code until it works. B) looking online for the answers. C) developing an algorithm.

C) developing an algorithm.

Methods are used to A) Allow code reuse B) Reduce code complexity and length C) Make program maintenance easier. D) All of these reasons

D) All of these reasons

This statement ends a loop immediately: A) HALT B) CONTINUE C) ESCAPE D) BREAK

D) BREAK

Type of expression used to control loops: A) Break B) Bubble C) Binary D) Boolean

D) Boolean

Visibility (public versus private) in a class is important because A) It allows overloading methods. B) It confuses students. C) It allows creating new objects from a class. D) It enforces encapsulation.

D) It enforces encapsulation.

(T/F) Coding a class creates a new simple data type.

FALSE

(T/F) Input is sending messages to the console/user.

FALSE

(T/F) Methods should be marked private and attributes should be marked public.

FALSE

(T/F) Only the main method can call another method.

FALSE

(T/F) Output is process of reading information from user, usually via keyboard or mouse.

FALSE

(T/F) Pseudocode form of writing should be used only when the logic of the program is complex.

FALSE

(T/F) String is a primitive data type.

FALSE

(T/F) The statement int[] list = {5, 10, 15, 20}; (C# & Java) int list[] = {5,10,15,20}; (C++) gives an error since there is no new reserved word included in the statement.

FALSE

(T/F) A linear search is ALWAYS more efficient than a binary search.

False

(T/F) Arrays can hold multiple types of data in one array.

False

(T/F) ONLY while loops can be nested.

False

(T/F) BEGIN MAIN END MAIN This is a valid skeleton program for Pseudocode.

TRUE

(T/F) A flowchart is a type of diagram that represents an algorithm, workflow or process.

TRUE

(T/F) A logical operator used when comparing primitive data types is !=.

TRUE

(T/F) A switch statement is similar to an if statement in that both are used to alter the flow of a program if the specified test condition is true.

TRUE

(T/F) An array index cannot be of the double, float or String data types.

TRUE

(T/F) If the expression xyz % 3 == 0 is true and xyz is a positive integer, then the value stored in the variable xyz is evenly divisible by 3.

TRUE

(T/F) In general, the advantage of using a binary search over a linear search increases when searching larger sorted arrays.

TRUE

(T/F) Is this valid syntax for a FOR loop? for(int j = 0; j < 1000; j++) x--; // where x is a positive integer

TRUE

(T/F) Once an array is created, it cannot be resized during program execution.

TRUE

(T/F) Software testing involves the execution of a software component or system component to evaluate one or more properties of interest.

TRUE

(T/F) The top of the runtime stack is the currently running method.

TRUE

(T/F) Arrays must be sorted for a Binary Search to work correctly.

True

(T/F) Constructors do not have a return type declared in the header.

True

(T/F) variables can be declared and initialized in one line of code.

True

8 Simple data types

byte, int, short, long, double, float, boolean, char

Write the code that declares an array of DOUBLES, called myArray, with a size of 100 elements.

double myArray[] = new double[100];


Ensembles d'études connexes

You're welcome B*tches!! A Sociology of the Family Inquisitive

View Set

Musculoskeletal Disorders and Blood Disorders

View Set

Chapt. 31, 32, 33 Immune System (Prep U)

View Set

Commonlit: The Open Boat Assessment

View Set