CSCE 111 practice questions

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

. ____________ is the process of inspecting data given to the program by the user and determining if it is reasonable. a. Data parsing b. Input validation c. Garbage collection d. Defensive coding e. Process Inspection

b

.You can use this method to determine whether a file exists. a. The Scanner class's exists method b. The File class's exists method c. The File class's canOpen method d. The PrintWriter class's fileExists method e. Java throws statement

b

Given the following statement, which statement will write "AGGIES" to the file DiskFile.txt? PrintWriter pwtr = new PrintWriter("DiskFile.txt"); a. System.out.println(diskOut, " AGGIES"); b. pwtr.println("AGGIES"); c. DiskFile.println("AGGIES"); d. PrintWriter.println("AGGIES"); e. None of the above

b

In the following Java statement what value is stored in the variable name? String name = "Hillary Trump"; a. Hillary Trump b. The memory address where "Hillary Trump" is located c. The word name d. A sequence of bits representing the ascii character values of "Hillary Trump" e. C and D

b

The import statement : a. is needed if the class to be imported is in the same package b. allows access to classes defined elsewhere c. retrieves user input d. copies text, verbatim, from a file e. none of the above

b

The name of a variable is known as its a. Constant b. Identifier c. Data type d. Object e. Method

b

What is the output of the following code fragment? String x = "Java rules!"; String y = "TAMU!"; if (y.charAt(3) == x.charAt(1)) System.out.println(y.length()); else System.out.println(x.length()); a. 10 b. 11 c. 4 d. 5 e. 0

b

What is the output of the following code? int a = 2, b = 2; while (--a > 0 && b++ > 0){ System.out.println(a + " " + b); } a. 2 2 b. 1 3 c. 2 4 d. 2 2 3 1 4 0 e. It is an infinite loop

b

What value is not stored in the array? int[] array = new int[10]; for (int i = 0; i < array.length; i++) array[i] = i; System.out.println(array[4]); a. 0 b. 10 c. 4 d. 9 e. 7

b

What will be the value of sum after the following code is executed? int sum, left = 5, middle = 1, right = 4; sum = (left++) * (middle++) / (++right); a. 0 b. 1 c. 2 d. 3 e. None of the above

b

What would be the value of x after the following statements were executed? int x = 17; switch (x){ case 17: x += 15; case 18: x -= 5; case 20: x = 10; break; default: x *= 3; } a. 12 b. 10 c. 27 d. 51 e. 32

b

Which of the following would be a valid method call for the following method? public static void decideWinner (char c, int num1, double num2) { int winner; winner = num1 * (int)num2; System.out.println("The winner is " + winner); } a. decideWinner ('d', 4.1, 3.0); b. decideWinner ('a', 4, 2); c. decideWinner ("c", 9, 2.1); d. decideWinner ('b', 3.7, 5); e. All of the above

b

A Java program must have one of these: a. Variable b. Comment c. System.out.println(); statement d. Main method e. Scanner definition

d

A syntax error differs from a runtime error in that : a. syntax errors occur while a program is running b. syntax errors are often missed be the compiler c. syntax errors are harder to fix than runtime errors d. syntax errors are reported by the compiler e. they are the same

d

Each repetition of a loop is known as what? a. A cycle b. An execution c. A lap d. An iteration e. A circulation

d

Local variables can be initialized with a. constant values b. values passed into the method via parameters c. the results of an arithmetic operation d. All of the above e. only A and B

d

RAM is usually: a. Secondary storage b. An input/output device c. A static type of memory, used for permanent storage d. A volatile type of memory, used only for temporary storage e. A type of memory only used to store random values

d

The keyword 'new': a. starts a new program b. clears the value from a variable c. opens a new file in the editor d. allocates memory for the object e. none of the above

d

The purpose of validating the results of the program is: a. To create a model of the program b. To correct syntax errors c. To correct runtime errors d. To make sure the program solves the problem e. B and C

d

Variables are: a. Operators that perform operations on one or more operands b. Reserved words c. Symbolic names made up by the programmer whose values cannot be changed d. Symbolic names made up by the programmer that represent locations in the computer's RAM e. None of the above

d

What is the value of z after the following code has been executed? int x = 13; int y = 16, z = 6; if (y < x); z += x; a. 6 b. 13 c. 8 d. 19 e. This code will not compile

d

What will be printed after the following code is executed? for (int number = 5; number <= 10; number -=3) System.out.print(number + ", "); a. 5, 6, 7, 8, 9, 10 b. 5, 7, 10 c. 5, 8 d. An infinite series of numbers e. This is an invalid for statement

d

What will be printed when the following code is executed? double x = 13579.246; DecimalFormat formatter = new DecimalFormat("#,##0.0"); System.out.println(formatter.format(x)); a. 1357.9 b. 13579.25 c. 13579.2 d. 13,579.2 e. There is an error in how DecimalFormat is used

d

When an object, such as a String, is passed as an argument, it is a. copied into another memory location, and the new location is given to the method b. encrypted for security c. necessary to know exactly how long the string is when writing the program d. actually a reference to the object that is passed e. All of the above

d

Which of the following are pre-test loops? a. while, for,if,do-while b. while, do-while c. for, do-while d. while, for e. for,if,while

d

Which of the following values can be passed to a method that has an int parameter variable? a. int b. short c. double d. A and B e. All of the above

d

. A program is a sequence of instructions stored in: a. The CPU b. The motherboard c. Software d. Firmware e. Memory

e

Class objects normally have __________ that perform useful operations on their data, but primitive variables do not. a. static keywords b. instances c. variables d. fields e. methods

e

Consider the following program: for (int loop1 = 0; loop1 <= 11; loop1++) for (int loop2 = 0; loop2 <= 11; loop2++) System.out.println("1"); How many lines of output will be printed? a. 1 b. 10 c. 11 d. 121 e. 144

e

Each different type of CPU has its own: a. Syntax b. Firmware c. Software d. Operating System e. Machine language

e

How many "USA" are displayed from the following code fragment? int count = 0; while (count < 8) System.out.println("USA"); count++; a. 0 b. 1 c. 7 d. 8 e. Infinite

e

In Java, ___________ must be declared before they can be used. a. Memory blocks b. Literals c. Key words d. Comments e. None of the above

e

Key words are: a. The data names in your program b. Words that have a special meaning in the programming language c. Words that cannot be re-defined by the programmer d. Symbols or words that perform operations on one or more operands e. B and C

e

Local variables a. may not have the same name as local variables in other methods b. are only meant for use in the method they are declared c. are only available to other methods in the class d. lose the values stored in them between calls to the method in which the variable is declared e. B and D

e

Methods are commonly used to a. speed up the compilation of a program b. emphasize certain parts of the logic c. document the program d. break up variable declarations into several phases e. break a problem down into small manageable pieces

e

The major components of a typical computer system consist of: a. The CPU b. Input/output devices c. Main memory d. Secondary storage devices e. All of the above

e

The method header must specify: a. The method's local variable names b. The parameters of the method c. The data type of the return value d. The class the method belongs to e. B and C

e

What does the following code display? int a = 6; double b = 16.2; System.out.printf("%2.3f %4d\n", b, a); a. %2.3f %4d\n b. 37.260 24 c. %12.100 %6\n d. 16.20 6 e. 16.200 6

e

What is wrong with this code? class TestClass{ public static void main(String [] args){ int x = 0; double y = 3; if (x == y) System.out.println("Equal"); if (x < y) System.out.println(x + " is less"); } } a. The System.out.println statements should be within braces b. The variable y should be declared as 3.0 c. In the print statement, x should be in quotes d. Cannot compare x (int) with y (double) e. There is nothing wrong

e

What will be displayed as a result of executing the following code? int x = 5, y = 14; x += 30; if ( x > 32) y /= 4; System.out.println("x = " + x + ", y = " + y); a. x = 5, y = 14 b. x = 5, y = 44 c. x = 35, y = 3.5 d. x = 30, y = 4 e. x = 35, y = 3

e

What will be displayed as a result of executing the following code? public class Test { public static void main(String[] args) { int value1 = 15; System.out.println(value1); int value2 = 10; System.out.println(value2); System.out.println(value3); int value3 = 3; } } a. 15 10 3 b. 15103 c. 15 10 3 d. value1 value2 value3 e. Nothing, there is a compile error

e

What will be printed when the following code segment is executed? int y = 32; if ( y <= 40) { int x = 30; x += y; } System.out.print("x = "); System.out.print(x); a. x = 70 b. x = 72 c. x = 30 d. x = 0 e. Nothing, there will be a compile error

e

What will be the result of the following code? int num; String str = "777"; num = Integer.parseInt(str) + 7; a. neither num or str will be changed b. str will have a value of "777" c. both variables will have the value of "777" d. the last line of code will cause an error e. None of the above

e

What will be the value of a after the following code is executed? int a = 3, b = 17; while (b < 100) { a += b; b -= a; } a. 3 b. 20 c. 100 d. 19,804 e. This is an infinite loop

e

What will be the values of ans, x, and y after the following statements are executed? int ans = 5, x = 25, y = 20; if ( x >= y){ ans = x + 10; x -= y; } else{ if (x < y){ ans = y + 10; } y += x; } a. ans = 35, x = 15, y = 25 b. ans = 30, x = 5, y = 45 c. ans = 5, x = 20, y = 40 d. ans = 30, x = -5, y = 20 e. None of the above

e

Where does the interpreter begin execution? a. The first class b. At the first conditional statement in the code c. The first method that is public d. The first method listed in the class e. None of the above

e

Which method return type is invalid? a. int b. double c. Scanner d. String e. class

e

Which of the following is a primitive data type? a. short b. long c. float d. B and C e. All of the above

e

Which one of these is a valid comment in Java? a. <% This is a comment % b. \\This is a comment c. COMMENT: This is a comment d. /\ This is a comment /\ e. None of the above are valid

e

. When the continue statement is encountered in a loop, the execution continues from the beginning of the body of the loop.

F

A byte can contain either 32 or 64 bits

F

A declared variable is always visible to the entire method in which it is declared.

F

A return statement used in a void method terminates the program.

F

A variable's scope is always the entirety of the class in which the variable is declared.

F

According to the Java standard naming convention class names and variables must start with an upper case letter and must contain a number.

F

An array index can be a double value

F

Each byte is assigned a unique number known as a bytecode.

F

In Java, a method call only be executed once.

F

In a for statement, the control variable must be incremented by 1 for each iteration

F

In computers, data is stored in hexadecimal form, which is denoted as 0x00 - 0x11

F

Java runs differently on different CPU architectures.

F

Since the do-while loop always executes for at least one iteration, it requires its condition to be true for the first iteration.

F

Suppose we have the following declarations: int a = 5, b = 3; is (a * (b/a) == 3) true or false?

F

The PrintWriter class will append to an already existing file

F

The following code fragment results in an infinite loop. int i=100; while (i != 100){ i--; }

F

The private method modifier means the method is available to code outside the class

F

What is the value of b after executing these statements? boolean b; int x = 10, y = 7, z = 10; if (x > y && y > z) b = true; if (y < z || x > y) b = false; if (x < z || y > x && z < x) b = true;

F

When two Strings are compared using the equals method, their cases are ignored.

F

. In the Java programming language, an argument is used to ________________. a. provide values to an invoked method b. override the object's default method definition c. define constants in any given program d. perform mathematical tasks (especially algebraic) in Java e. let the Java compiler know the purpose of the method

a

A parameter variable's scope: a. is the method in which the parameter is declared b. is the class to which the method belongs c. always includes the main method d. B and C e. None of the above

a

This is a value that signals when the end of a list of values has been reached. a. Sentinel b. Terminal c. Final d. End value e. False boolean

a

To determine the value of an array during runtime each array has a field associated with it called: a. length b. size c. numberOfElements d. howBig() e. arrays do not have any variable associated with them

a

What will be the values of x and y as a result of the following code? int x = 4, y = 7; x += y++; y = --x + --x; x *= y--; a. x = 171, y = 18 b. x = 209, y = 19 c. x = 210, y = 20 d. Invalid operation e. None of the above

a

When a computer is running a program, the CPU is engaged in a process formally known as: a. The fetch/decode/execute cycle b. The decrypt/validate/commit cycle c. Low-level machine mode d. Parallax data execution e. Decision selection

a

Which of the following will open a file named SomeText.txt and allow you to read data from it? a. File file = new File("SomeText.txt"); Scanner inputFile = new Scanner(file); b. File file = new File("SomeText.txt");c. c. PrintWriter inputFile = new PrintWriter("SomeText.txt"); d. Scanner inputFile = new Scanner("SomeText.txt"); e. File file = new File("SomeText.txt"); Scanner inputFile = new Scanner(System.in);

a

. A class defines how the object created from this class will work

T

. Because the || operator performs short-circuit evaluation, your boolean expression will generally be evaluated faster if the subexpression that is most likely to be true is on the left

T

A method can take values of expressions as arguments

T

A value-returning method can return a reference to a non-primitive type

T

Java provides unary operators that let the programmer increment and decrement variables

T

Local variables are stored in an area of memory called stack

T

Logical errors are mistakes that are not caught by the compiler

T

System.out.print, the nextInt in the Scanner class and main are all "methods".

T

The Java Virtual Machine is responsible for executing Java byte code.

T

The word import in a Java program is a key word reserved by the language

T

When you use the Scanner class, the class can potentially throw an IOException

T

. Given the following code, what will be output? public class Order { private int orderNum; private double orderAmount; private double orderDiscount; public Order(int orderNumber, double orderAmt, double orderDisc) { orderNum = orderNumber; orderAmount = orderAmt; orderDiscount = orderDisc; } public int getOrderTotal() { return orderAmount - (orderAmount * orderDiscount); } public int getOrderDisc() { return orderDiscount; } } public class CustomerOrder { public static void main(String[] args) { int x = 2253; double y = 4.00; double z = 0.25; Order order = new Order(x, y, z); double finalAmount = order.getOrderTotal(); System.out.printf("Final order amount = %.2f", finalAmount); } } a. Final order amount = $4.00 b. Final order amount = $0.25 c. Final order amount = $3.00 d. There is an error in the code of the Order class. e. There is an error because the object order has not been created correctly.

c

. If method A calls method B, and method B calls method C, and method C calls method A, when the last call to method A finishes, what happens? a. control is returned to method A b. control is returned to method B c. control is returned to method C d. control is returned to the last referenced variable e. the program terminates

c

. The values of local variables: a. retain their values from the last call to the method in which they are declared b. may be referenced by the calling method c. are lost between calls to the method in which they are declared d. may be referenced by any other method, if the method in which they are declared is a public method e. Both C and D

c

For the following code, which statement is not true? public class Car { private String make; public double price; private int year; private String owner; } a. price is available to code that is written outside the Car class. b. make is not available to code written outside the Car class. c. owner is available to code that is written outside the Car class. d. make, price, year, and owner are called data fields of the Car class. e. Class Car can have both public and private fields, even though it is declared public

c

How many times will the following for loop be executed? for (int count = 15; count <= 26; count++) System.out.println("How many times?"); a. 0 b. 11 c. 12 d. 21 e. Infinite

c

If chr is a character variable, which of the following if statements is written correctly? a. if (chr = "h") b. if (chr == "e") c. if (chr == 'l') d. if (chr = 'l') e. if (chr == o)

c

If the following Java statements are executed, what will be displayed? System.out.println("The top three teams are\n\n"); System.out.print("New England Patriots\n"); System.out.print("Greenbay Packers"); System.out.println("Seattle Seahawks"); a. The top three teams are New England Patriots Greenbay Packers Seattle Seahawks b. The top three teams are New England Patriots\ nGreenbay Packers Seattle Seahawks c. The top three teams are New England Patriots Greenbay PackersSeattle Seahawks d. The top three teams are\n New England Patriots\nGreenbay PackersSeattle Seahawks e. There is an error in the code

c

The phrase divide and conquer is sometimes used to describe a. the backbone of the scientific method b. the process of dividing functions c. the process of breaking a problem down into smaller pieces d. the process of using division to solve a mathematical problem e. the process of using different objects to hold different data

c

This type of loop is ideal in situations where the exact number of iterations is known. a. while b. do-while c. for d. if e. Either A or B

c

What is the output of the following code segment? System.out.print("A\t" + 4 + "\tB"); a. A4B b. A 4B c. A 4 B d. A A A A B e. Invalid statement

c

What will be the output after the following statements have been executed? int x = 5, y = 13; double z; z = (double)(y / x); z += y; z -= x; System.out.print(z); a. 15.66666667 b. -6.67 c. 10.0 d. -17 e. Code will cause an error

c

What would be the value of bonus after the following statements are executed? int bonus, sales = 2500; if (sales > 2000) bonus = 1000; if (sales > 500) bonus = 250; if (sales > 50) bonus = 25; else bonus = 0; a. 1000 b. 250 c. 25 d. 0 e. None of the above

c

When you pass an argument to a method, a. all public data members of the class are updated with the value of the argument b. its value will be changed within the called method c. it initializes the parameter variable in the method definition d. the method must not assign another value to the parameter that receives the argument e. A and B

c

Which of the following is valid? a. short x; int y; double z; x = y = z = 3; b. String y; char z; z = 'a'; y = z; c. float w; double v; w = 1.0f; v = w; d. float v; int y; v = 5.0; y = v; e. None of the above

c


Set pelajaran terkait

Earth Science - Unit 9: Earth's Atmosphere. Lesson 1:Evolution of the Atmosphere

View Set

ATI Fundamentals 3.0: Fundamentals

View Set

Chapter 50: Care of Patients with Musculoskeletal Problems

View Set

Chapter 13 Real Estate Taxes and Other Liens

View Set

Bio- unit1- notes from book pt2- ch 3, 32, 16

View Set

Perioperative and Mobility Escape Room

View Set