Programming II Exam 2 Study

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Q063 Which operator is used to invert a conditional statement?1 pts Which of the following operators is used to invert a conditional statement?

!

Q037 What is a Java "class" file?1 pts A Java "class" file _______________________.

contains instructions to the Java virtual machine

Q080 Which operator is used to concatenate two or more strings?1 pts Which operator is used to concatenate two or more strings?

+

Q005 What is the range of index values for an array of size 10?1 pts What is the valid range of index values for an array of size 10?

0 to 9

Q083 What is the size of the given array list after add(10.5)?1 pts Consider the following code snippet: ArrayList<Double> somedata = new ArrayList<Double>(); somedata.add(10.5); What is the size of the array list somedata after the given code snippet is executed?

1

Q035 What is the value of Math.abs(-2)?1 pts What is the value of Math.abs(-2)?

2

Q092 Which statement is true about declaring an array list as a method parameter?1 pts Which one of the following statements about declaring an array list as a method parameter is true?

An array list value can be modified inside the method.

Q039 Which statement about reading and writing text files is correct?1 pts When reading words with a Scanner object, a word is defined as ____.

Any sequence of characters that is not white space.

Q007 Which statement about closing files is correct?1 pts Which of the following statements reflects the recommendations about closing files?

Both the input and the output file should be explicitly closed in the program.

Q048 Which statement is true about passing arrays to a method?1 pts Which one of the following statements is true about passing arrays to a method?

By default, arrays are passed by reference to a method

Q067 How are command line arguments handled?1 pts Which of the following statements about command line arguments is correct?

Command line arguments can be read using the main method's args parameter

Q055 What do the diamond-shaped boxes indicate in a flow chart?1 pts The flow chart shows the order in which steps should be executed, and the diamond-shaped boxes indicate ______________.

Conditional tests

Q012 Which statement about a PrintWriter is true?1 pts Which of the following statements about a PrintWriter object is true?

Data loss may occur if a program fails to close a PrintWriter object before exiting.

Q047 Which statement is true about the main method?1 pts Which of the following statements is true with respect to the main method in Java?

Every Java application must have a main method.

Q008 What is the correct syntax for creating a File object?1 pts Which of the following is the correct syntax for creating a File object?

File inFile = new File("input.txt")

Q028 Which is the correct code for opening an input file?1 pts Your program wishes to open a file named C:\java\myProg\input.txt on a Windows system. Which of the following is the correct code to do this?

File inputFile = newFile("c:\\java\\myProg\\input.txt");

Q025 What can be used as an argument in a method call?1 pts What can be used as an argument in a method call? I. A variable II. An expression III. Another method call that returns a value IV. Another method call that has no return value

I, II and III

Q008 Which statement(s) is true about an if statement?1 pts Which of the following statements is (are) true about an if statement? I. It guarantees that several statements are always executed in a specified order. II. It repeats a set of statements as long as the condition is true. III. It allows the program to carry out different actions depending on the value of a condition.

III only

Q066 Which condition tests for the string "Hello"?1 pts Which of the following conditions tests for the user to enter the string "Hello"? String s; Scanner in = new Scanner(System.in); System.out.print("Enter a word: "); s = in.next();

If (s.equals("Hello"));

Q015 Select correct expression to construct PrintWriter object1 pts Select an expression to complete the following statement, which is designed to construct a PrintWriter object to write the program output to a file named dataout.txt. PrintWriter theFile = _______________________;

If a file named "output.txt" already exists, existing data will be deleted before data are added to the file.au

Q080 Which statement about exceptions is true?1 pts Which statement about handling exceptions is true?

If an exception has no handler, the program will be terminated.

004 Which statement about PrintWriter is correct?1 pts Which of the following statements about using the PrintWriter object is correct?

If the output file already exists, the existing data will be discarded before new data are written into the file.

Q005 When does PrintWriter generate a FileNotFoundException?1 pts Under which condition will the PrintWriter constructor generate a FileNotFoundException?

If the output file cannot be opened or created due to a security error.

Q043 What is white space?1 pts Which of the following statements about white space in Java is correct?

In Java, white space includes spaces, tab characters, and newline characters.

Q098 How should methods be invoked on string variables?1 pts What is the correct way to invoke methods on variables in Java that are strings?

Invoke them using the variable name and the dot (.)

Q072 What is the purpose of the throw statement?1 pts What is the purpose of the throw statement?

It is used to pass control to an error handler when an error situation is detected.

Q010 What is the error in this if statement?1 pts The following code snippet contains an error. What is the error? if (cost > 100); { cost = cost - 10; } System.out.println("Discount cost: " + cost);

Logical error: if statement has do-nothing statement after if condition

Q010 Which is not legal in a method definition?1 pts Which of the following is not legal in a method definition?

Multiple return values

Q088 What is the scope of local variable1 pts What is the output of the following code snippet? public static void main(String[] args) { int gvar = 0; gvar = gvar + 10; if (gvar > 0) { int lvar = gvar + 1; } System.out.println(lvar); }

No output due to compilation error

Q078 Identify correct expression to use in catch clause1 pts Select an expression to complete the program segment below, which displays an error message and terminates normally if the String variable accountNumber does not contain an integer value. try { int number = Integer.parseInt(accountNumber); } catch ( ________________________ ) { System.out.println("Account number is not an integer value"); }

NumberFormatException exception

Q009 Which is correct (about variable names)?1 pts Consider the following Java variable names: I. 1stInstance II. basicInt% III. empName_ IV. addressLine1 V. DISCOUNT Which of the following options represent valid Java variable names?

Only III, IV, and V are valid Java variable names

Q063 Using delimiters with the Scanner1 pts Consider the following code snippet: Scanner in = new Scanner(. . .); in.useDelimiter("[A-Za-z]+"); What characters will be read in using this code?

Only non-alphabetic characters will be read in.

Q002 Why is the term "black box" used with methods?1 pts The term "Black Box" is used with methods because

Only the specification matters; the implementation is not important

Q091 An example of a rare fatal error is ___.1 pts An example of a fatal error that rarely occurs and is beyond your control is the ____.

OutOfMemoryError

Q017 The PrintWriter class is an enhancement of the ____ class.1 pts The PrintWriter class is an enhancement of the ____ class.

PrintStream class

Q073 Which is NOT a good practice in developing a computer program?1 pts Which of the following is NOT a good practice when developing a computer program?

Put as many statements as possible into the main method

Q009 What are the parts of a method header?1 pts After the keywords "public static", what are the names (in order) of the parts of this method header? public static int myFun (double a)

Return type, method name, parameter variable type, parameter variable name

Q009 Which object should be used for reading from a text file?1 pts Which of the following objects should be used for reading from a text file?

Scanner

Q014 What is the correct syntax for opening a file with a Scanner object?1 pts Consider the following code snippet: File inputFile = new File("input.txt"); You wish to read the contents of this file using a Scanner object. Which of the following is the correct syntax for doing this?

Scanner in = new Scanner(inputFile)

Q024 A Java virtual machine is ___1 pts A Java virtual machine is ____________.

Software

Q029 What is a Java Virtual Machine?1 pts A Java Virtual Machine is _______________________.

Software

Q079 Which statement about exception handing is true?1 pts Which of the following statements about exception handling is correct?

Statements that may cause an exception should be placed within a try block.

Q027 What statement provides the desired output string from array?1 pts Consider the following code snippet. Which statement should be used to fill in the empty line so that the output will be [32, 54, 67.5, 29, 35]? public static void main(String[] args) { double data[] = {32, 54, 67.5, 29, 35}; ______________ System.out.println(str); }

String str = Arrays.toString(data);

Q061 Identify proper arguments to use with printf statement1 pts Assume inputFile is a Scanner object used to read data from a text file that contains a series of double values. Select an expression to complete the following code segment, which reads the values and prints them in standard output, one per line, in a field 15 characters wide, with two digits after the decimal point. while (inputFile.hasNextDouble()) { double value = inputFile.nextDouble(); ___________________________________ // statement to display double value }

System.out.printf("%15.2f\n",value);

Q001 Which code displays the 28th element of somearray?1 pts Consider the following line of code: int[] somearray = new int[30]; Which one of the following options is a valid line of code for displaying the twenty-eighth element of somearray?

System.out.println(somearray[27]);

Q041 What happens when an array runs out of space?1 pts When an array reading and storing input runs out of space, __________________.

The array must be "grown" using the new command and the copyOf method.

Q015 What is the error in this array code fragment?1 pts What is the error in this array code fragment? double[] data; data[0] = 15.25;

The array referenced by data has not been initialized.

Q085 Which statement about checked and unchecked exceptions is true?1 pts Which of the following statements about checked and unchecked exceptions is true?

The compiler ensures that the program is handling checked exceptions.

Q019 What is the expected type of the conditional in an if statement?1 pts Which statement about an if statement is true?

The condition in an if statement using relational operators will evaluate to a Boolean result

Q010 Which statement about exceptions is correct?1 pts Consider the following code snippet: public static void main(String[] args) throws FileNotFoundException Which of the following statements about this code is correct?

The main method should simply terminate if the FileNotFoundException occurs.

Q012 What is the error in this method definition?1 pts What is the error in the following method definition? public static int tripler(int numPara) { double result = numPara * 3; }

The method does not return a value.

Q056 What is a good rule for deciding the number of statements in a method1 pts What is a good rule for deciding the number of statements in a method?

The method should perform only one task and contain just enough statements for the task

Q094 Which statement about handling file exceptions is correct?1 pts Consider the following code snippet: PrintWriter outputFile = new PrintWriter(filename); writeData(outputFile); outputFile.close(); How can the program ensure that the file will be closed if an exception occurs on the writeData call?

The program should place the outputFile.close() statement within a finally clause of a try block to ensure that the file is closed

Q047 What is true about method that uses array?1 pts Consider the following method: public static int mystery(int length, int n) { int[] result = new int[length]; for (int i = 0; i < result.length; i++) { result[i] = (int) (n * Math.random()); } return result; } Which statement is correct about the code?

The return type is wrong; result is an array and it needs to return an int

Q088 If a method cannot handle an exception, what should be done?1 pts If the current method in a program will not be able to handle an exception, what should be coded into the method?

The throws clause should list the names of all exceptions that the method will not handle.

Q067 Which value of the 2-dimensional array arr is stored in arr[0][2]?1 pts Consider the following code snippet: int val = arr[0][2]; Which value of arr is stored in the val variable?

The value in the first row and the third column

Q062 Formatting output1 pts Consider the following code snippet, assuming that description is a String and totalPrice is a double: System.out.printf("%-12s%8.2f",description,totalPrice); Which of the following statements is correct?

This code will produce 2 columns, with the description field left justified and the totalPrice field right justified.

Q080 What is the purpose of writing a stub method?1 pts What is the purpose of writing a stub method?

To test another method without writing all the implementation details of a method called by the method being tested

Q087 Which statement about checked and unchecked exceptions is NOT true?1 pts Which of the following statements about checked and unchecked exceptions is NOT true?

Unchecked exceptions belonging to subclasses of the RunTimeException class are beyond the control of the programmer

Q018 Which statement about reading and writing text files is correct?1 pts Which of the following statements about reading and writing text files is correct?

You use the Scanner class to read text files and the PrintWriter class to write text files.

Q012 Which is an assignment statement?1 pts Which one of the following is an assignment statement?

a = 20;

Q010 What is an example of an input device that interfaces between humans and computers?1 pts An example of an input device that interfaces between computers and humans is ____________.

a microphone

Q071 Identify expression to open file using command line argument1 pts Select an expression to complete the program segment below, which is designed to read data from a file whose name is specified as the first command line argument. If no command line arguments are given, the program reads data from the default.txt file. String fileName = "default.txt"; if ( ________________________ ) { fileName = args[0]; } // additional statements to open file and read data

args.length > 0

Q096 Java performs _____ when adding primitive types to array list.1 pts When an integer literal is added to an array list declared as ArrayList<Integer>, Java performs ___________.

auto-boxing

Q097 What concept related to array lists does the given code represent?1 pts Consider an array list values declared as ArrayList<Double> that has been constructed and populated. What concept does the given code represent? double d = values.get(0);

auto-unboxing

Q026 Which option is the best variable name?1 pts Which option represents the best choice for a variable name to represent the average grade of students on an exam?

averageGrade

Q078 How do you compute the length of the string str?1 pts How do you compute the length of the string str?

str.length()

Q036 Where is Java source code stored?1 pts The source code for a Java program is stored in a file ________________.

that ends with a .java suffix

Q042 What does every statement end with?1 pts Every statement in Java must be terminated with ____________.

the semi-colon character

Q025 Handling a missing input file1 pts Insert the missing code in the following code fragment. This fragment is intended to read an input file named hoursWorked.txt. You want the program to terminate if the file does not exist. public static void main(String[] args)______________ { File inputFile = new File("hoursWorked.txt"); Scanner in = new Scanner(inputFile); . . . }

throws FileNotFoundException

Q049 How to remove spaces from a string1 pts Which String class method will remove spaces from the beginning and the end of a string?

trim()

Q039 Which loop executes before checking condition?1 pts Which of the following loops executes the statements inside the loop before checking the condition?

do

Q037 Which word defines the branch to be executed when none of the conditions are true?1 pts Consider a situation where multiple if statements are combined into a chain to evaluate a complex condition. Which of the following reserved words is used to define the branch to be executed when none of the conditions are true?

else

Q016 Which statement defines a constant?1 pts Which one of the following statements defines a constant with the value 123?

final int MY_CONST = 123;

Q029 Which declares a float variable?1 pts Which of the following options declares a float variable?

float age;

Q016 What is the correct enhanced for loop to iterate over the array1 pts Complete the following code snippet with the correct enhanced for loop so it iterates over the array without using an index variable. String[] arr = { "abc", "def", "ghi", "jkl" }; ___________________ { System.out.print(str); }

for (String str: arr)

Q033 Which of the following for loops is illegal?1 pts Which of the following for loops is illegal?

for (int i = 0) { }

Q054 Select correct expression to test for integer values in a text file1 pts Assume inputFile is a Scanner object used to read data from a text file that contains a number of lines. Some lines contain an alphabetic string, while others contain a single integer value. Select an expression to complete the following code segment, which counts the number of integer values in the input file. int count = 0; while (inputFile.hasNextLine()) { if (________________________________) { count++; } inputFile.nextLine(); } System.out.println(count);

inputFile.hasNextInt()

Q038 Select correct expression to input String objects from a text file1 pts Assuming that inputFile is a Scanner object used to read words from a text file, select an expression to complete the following code segment, which counts the number of words in the input file. int count = 0; while (inputFile.hasNext()) { String word = _______________; count++; } System.out.println(count);

inputFile.next()

Q047 Character testing methods1 pts The ____ method of the Character class will indicate if a character contains white space.

isWhiteSpace()

Q103 Which command enables assertion checking during program execution?1 pts Which command enables assertion checking during program execution?

java -enableassertions MainClass

Q068 How are command line arguments entered?1 pts Which of the following is the correct syntax for starting a Java program named myProg from a command line if the program requires two arguments named arg1 and arg2 to be supplied?

java myProg arg1 arg2

Q001 Complete code for reading an input file1 pts Insert the missing code in the following code fragment. This fragment is intended to read an input file named dataIn.txt. public static void main(String[] args) throws FileNotFoundException { String inputFileName = "dataIn.txt"; File inputFile = new File(inputFileName); Scanner in = _______________; . . . }

new Scanner(inputFile);

Q024 Which is best choice for declaring method that calculates volume of cuboid?1 pts Suppose you need to write a method that calculates the volume of a 3D rectangular solid. Which of the following is the best choice for the declaration of this method?

public static double volume(double w, double h, double l)

Q024 Handling file exceptions1 pts Your program must read in an existing text file. You want the program to terminate if any exception related to the file occurs. Which of the following indicates the correct code for the header of the main method?

public static void main(String[] args) throws FileNotFoundException

Q039 What does the last element of data2 contain after an array copy?1 pts Consider the following code snippet in Java 6 or later: String[] data = { "abc", "def", "ghi", "jkl" }; String[] data2 = Arrays.copyOf(data, data.length - 1); What does the last element of data2 contain?

"ghi"

Q041 Which operator computes the remainder of an integer division?1 pts Which one of the following operators computes the remainder of an integer division?

% modulo

Q021 Which condition avoids division by zero?1 pts Which condition, when supplied in the if statement below in place of (. . .), will correctly protect against division by zero? if (. . .) { result = grade / num; System.out.println("Just avoided division by zero!"); }

(num != 0)

Q001 How many iterations of while loop?1 pts How many times will the following loop run? int i = 0; while (i < 10) { System.out.println(i); i++; }

10

Q027 How many times does for loop execute?1 pts How many times does the loop execute in the following code fragment? int i; for (i = 0; i < 50; i = i + 4) { System.out.println(i); }

13

Q008 How many times does while loop display result?1 pts How many times does the code snippet below display "Hello"? int i = 0; while (i != 15) { System.out.println("Hello"); i++; }

15

Q007 Which statement DOES NOT correctly compute the discount?1 pts A store provides 10 percent discount on all items with a price of at least $100. No discount is otherwise applicable. Which of the following DOES NOT correctly compute the discount?

2. discount = 0.10 * priceif price <= 100 :discount = 0

Q063 How many elements can be stored in an array of dimension 5 by 6?1 pts How many elements can be stored in a two-dimensional 5 by 6 array?

30

Q004 What are values of the elements at the given array indexes?1 pts What is the output of the following code snippet? int[] myarray = { 10, 20, 30, 40, 50 }; System.out.print(myarray[2]); System.out.print(myarray[3]);

3040

Q004 Which is the correct syntax for an if statement?1 pts Which of the following is the correct syntax for an if statement?

A condition and a body

Q033 Which is true about method return statements?1 pts Which of the following is true about method return statements?

A method can hold multiple return statements, but only one return statement executes in one method call.

Q079 What is a stub method?1 pts A stub method is ___________________.

A method that acts as a placeholder and returns a simple value so another method can be tested

Q032 What kinds of tools are included in an IDE?1 pts An integrated development environment (IDE) bundles tools for programming into a unified application. What kinds of tools are usually included?

An editor and a compiler

Q061 Which operator is used to combine two Boolean conditions?1 pts Which of the following operators is used to combine two Boolean conditions?

And operator (&&)

Q017 Which translates high-level descriptions into machine code?1 pts Which one of the following translates high-level descriptions into machine code?

Compiler

Q023 Software needed to translate Java source code1 pts In order to translate a Java program to a class file, the computer needs to have software called a(n) _______________.

Compiler

Q007 Which statements are true about array references?1 pts Which statements are true about array references? I. Assigning an array reference to another creates a second copy of the array. II. An array reference specifies the location of an array. III. Two array references can reference the same array.

II and III only

Q018 Which statements about the enhanced for loop are true?1 pts Which statements about the enhanced for loop are true? I. It is suitable for all array algorithms. II. It does not allow the contents of the array to be modified. III. It does not require the use of an index variable.

II, III only

Q015 What should be done to improve (program that does same calculation repeatedly)?1 pts In an accounting application, you discover several places where the total profit, a double value, is calculated. Which of the following should be done to improve the program design? I. The next time the total profit is calculated, use copy and paste to avoid making coding errors. II. Provide the same comment every time you repeat the total profit calculation. III. Consider writing a method that returns the total profit as a double value.

III. Consider writing a method that returns the total profit as a double value.

Q062 Which describes the process of stepwise refinement?1 pts Which of the following options describes the process of stepwise refinement? I. Using arguments to pass information to a method II. Using unit tests to test the behavior of methods III. Decomposing complex tasks into simpler ones

III. Decomposing complex tasks into simpler ones

Q001 Which is correct about a local variable?1 pts Which of the following is correct about a local variable?

It is declared within the scope of any method

Q058 What to use for rounding number?1 pts One way to avoid round-off errors is to use:

Math.round()

Q006 Which is true about methods?1 pts Which of the following is true about methods?

Methods can have multiple arguments and can return one return value.

Q037 Method return with multi-alternative "if" statement1 pts What is wrong with the following code? public static String grade(int score) { if (score >= 9) { return A; } else if (score >= 8) { return B; } else if (score >= 6) { return C; } else if (score >= 4) { return D; } return F; }

No return statement for all branches of "if" statement

Q034 Are these lines of code the same?1 pts Suppose you examine a simple Java program and the first line is public class HelloPrinter. Is this the same thing in Java as the line public class helloprinter?

No, because Java is case-sensitive, these are considered to be completely distinct

Q100 What type of error with code containing Integer.parseInt()?1 pts What (if any) type of error occurs with the following code if the user input is ABC? public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter a number: "); String str = in.next(); int count = Integer.parseInt(str); System.out.println("Input is " + count); }

Run-time error

Q017 What is the result of the enhanced for loop?1 pts What is the result of the following code? for (double element : values) { element = 0; }

The array values is not modified.

Q042 What happens to the fractional part (in integer division)?1 pts What happens to the fractional part when a division is performed on two integer variables?

The fractional part is discarded.

Q013 Which storage type provides data persistence without electricity? 1 pts Which of the following typically provides data persistence without electricity? I. The CPU's memory II. The hard disk III. Secondary storage

The hard disk and secondary storage

Q082 What is the result of this definition of an array list?1 pts What is the result of the following definition of an array list? ArrayList<Double> points;

The statement defines an array list reference but leaves its value as null.

Q034 What is problem with method?1 pts What is the problem with the definition of the following method that calculates and returns the tax due on a purchase amount? public static double taxDue(double amount, double taxRate) { double taxDue = 0.0; taxDue = amount * taxRate; }

The taxDue method does not return a value.

Q017 What is the error in this method definition?1 pts What is the syntax error in the following method definition? public static String parameter(double r) { double result; result = 2 * 3.14 * r; return result; }

The value that is returned does not match the specified return type

Q025 Which statement about Boolean conditions is true?1 pts When hand-tracing a portion of code, which statement about Boolean conditions is true?

They are crucial to evaluate since they determine if-statement conditions and looping.

Q047 What is the purpose of methods without a return value?1 pts The purpose of a method that returns void is __________________.

To package a repeated task as a method even though the task does not yield a value

Q007 Which statement about variable names is true?1 pts Which statement is true?

Variables cannot be assigned and declared in the same statement. Variable names must contain at least one dollar sign

Q022 Software needed to run Java on a computer1 pts In order to run Java programs on a computer, the computer needs to have software called a(n) __________.

Virtual Machine

Q041 What is a switch statement in Java?1 pts The switch statement in Java ________________.

a multiple alternative decision structure that allows you to test the value of a variable or an expression and then use that value to determine which statement or set of statements to execute.

Q018 Which of the following guidelines will make code more explanatory for others?1 pts Which of the following guidelines will make code more explanatory for others?

add comments to source code

Q040 Which code is correct to grow the size of an array?1 pts Consider the following code snippet: String[] data = { "abc", "def", "ghi", "jkl" }; Using Java 6 or later, which statement grows the data array to twice its size?

data = Arrays.copyOf(data, 2 * data.length);

Q038 Which code is correct to copy from one array to another?1 pts Consider the following code snippet: String[] data = { "abc", "def", "ghi", "jkl" }; String [] data2; In Java 6 and later, which statement copies the data array to the data2 array?

data2 = Arrays.copyOf(data, data.length);

044 Choose the loop that is equivalent to this loop.1 pts Choose the loop that is equivalent to this loop. int n = 1; double x = 0; double s; do { s = 1.0 / (n * n); x = x + s; n++; } while (s > 0.01);

double x = 0; double s = 1; for (int k = 1; s > 0.01; k++) { s = 1.0 / (k * k); x = x + s; }

Q023 What condition evaluates to true if the length of a string s1 is odd?1 pts What is the conditional required to check whether the length of a string s1 is odd?

if ((s1.length() % 2) != 0)

Q009 Which condition for an if statement is correct?1 pts Suppose one needs an if statement to check whether an integer variable pitch is equal to 440 (which is the frequency of the note "A" to which strings and orchestras tune). Which condition is correct?

if (pitch == 440)

Q030 Which condition tests for single digit input?1 pts Which of the following conditions tests whether the user enters the single digit 5? String s; Scanner in = new Scanner(System.in); System.out.print("Enter a single digit: "); s = in.next();

if (s.equals("5"))

001 Which defines an integer variable?1 pts Which of the following options defines an integer variable?

int age;

Q002 Which correctly defines and initializes an integer variable value?1 pts Which one of the following is a correct method for defining and initializing an integer variable with name value?

int value = 30;

Q003 Which array initialization statement is invalid?1 pts Which one of the following statements is a valid initialization of an array named somearray of ten elements?

int[ ] somearray = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

Q002 Which statement defines integer array numarray with ten elements?1 pts Identify the correct statement for defining an integer array named numarray of ten elements.

int[] numarray = new int[10];

Q062 Which is correct definition for initializing a 2-dimensional array of three rows and two columns?1 pts Which one of the following is the correct definition for initializing data in a two-dimensional array of three rows and two columns?

int[][] arr ={ { 1, 1 }, { 2, 2 }, { 3, 3 } };

Q027 What's wrong with integer expression?1 pts What is wrong with the following code? int count = 2000 * 3000 * 4000;

integer overflow

Q007 What is the function of a CPU?1 pts The Central Processing Unit is primarily responsible for ______________.

performing program control and data processing.

Q031 What is the reason for the ranges for integer values in Java?1 pts The typical ranges for integers may seem strange but are derived from ___________.

powers of two because of base 2 representation within the computer

Q002 Which statement is true about the if statement?1 pts Which of the following statements is true about the if statement?

the else block if optional

Q081 Which statement gets an element from the array list?1 pts The following statement gets an element from position 4 in an array: x = a[4]; What is the equivalent operation using an array list?

x = a.get(4);

Q016 Insert appropriate code in while loop1 pts Select the statement that correctly completes the loop in this code snippet. int years = 20; double balance = 10000; while (years > 0) { __________ double interest = balance * rate / 100; balance = balance + interest; }

years--;

Q015 Which statement is correct about constants?1 pts Which of the following statements is correct about constants?

you can make a variable constant by using the "final" reserved word when declaring it.


Kaugnay na mga set ng pag-aaral

CSS: Grid Essentials and Advanced Grid

View Set

marginal revenue= marginal cost approach

View Set

Finance Exam 1- Practice Exam Questions

View Set

Module 08 Networking Threats, Assessments, and Defenses

View Set

7 - Life Insurance Underwriting and Policy Issue

View Set

Ch. 13 Med-Surg: Palliative and End-of-Life Care

View Set

Money and banking test #3 top hat

View Set