COSC

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

What will be the results of the following code final int ARRAY_SIZE = 5; float[] x = float[ARRAY_SIZE]; for(int i = 1; i <= ARRAY_SIZE; i++) { x[i] = 10.0; }

An error will occur when the program runs off by 1 error

There is a file named "alreadyThere.txt" that needs to be opened for writing but not erased if it already exists

FileWriter fw = new FileWriter("alreadyThere.txt, true); PrintWriter fw = new PrintWriter(fw); outputFile.println("writing");

Which of the following will open a file named MyFile.txt and allow you to append data to its existing contents?

FileWriter fwriter = new FileWriter("MyFile.txt", true); PrintWriter outFile = new PrintWriter(fwriter);

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

Loop

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

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

do-while loop

t/f A sorting algorithm is used to locate a specific item in a larger collection of data

false

t/f Along with the file name, you have to state the boolean value false when creating a FileWriter object to allow content to be added to a file

false

t/f If a[] and b[] are two integer arrays, the expression a == b compares the array contents

false

t/f In a for statement, the control variable can only be incremented.

false

This ArrayList class method deletes an item from an ArrayList

remove

t/f The String[] args parameter in the main method header allows the program to receive arguments from the operating system command-line.

true

t/f You can use the PrintWriter class to open a file for writing and write data to it.

true

t/f You should include the file extension in your file names

true

The sequential search algorithm

uses a loop to sequentially step through an array, starting with the first element

What will be the value of x after the following code is executed? int x = 10; for(int y = 5; y < 20; y +=5) x += y;

40

The __ () method is used to determine the existence of a file

.exists()

What should be the data type if the file name?

String

Which of the statements are true about the following code final int ARRAY_SIZE = 10; long[] array1 = new long[ARRAY_SIZE];

*All of the above* -declares array1 to be reference to an array of lone values - creates an instance of an array of 10 long values -will allow valid subscripts in the range of 0-9

The __ () method reads a file until is runs into an end-of-file character

.hasNext

if final int SIZE = 15 and int [] x = new int[SIZE], what would be the range of subscript values that could be used with x[]?

0-14

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

1

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

100

What will be the value of x[8] after the following code has been executed?final int SUB = 12; int [] x = new int[SUB]; int y= 100; for(int i = 0; i < SUB; i++) { x[i] = y; y += 10; }

180

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

210

What will be the value of x after the following code is executed? int x, y = 15, z =3; x = (y--) / (++z);

3

What will be the value of x[8] after the following code has been executed final int SUB = 12; int[] x=new int[SUB]; int y= 20; for(int i = 0; i < SUB; i++) { x[i]=y; y+=5; }

60

What will be the result of executing the following code int[]x={0,1,2,3,4,5};

An array of 6 values ranging from -0 and referenced by the variable x will be created

A loop that executes as long as a particular condition exists is called a(n):

Conditional loop

What is the class necessary to create an object that is used to read a file

File

Which of the following will open a file named MyFile.txt and allow you to read data from it?

File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file);

Assume that a file "data.txt" exists. How do you prepare the file to be read by the program (java code)

File file = new File("data.txt"); Scanner inputFile = new Scanner(file); String str = inputFile.nextLine();

What is the class that is used to create an object that will allow a programmer/user to add data to a file rather than only just creating a file?

FileWriter

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

Infinite loop

This variable controls the number of times that the loop iterates

Loop control variable

What is the name of the class that is used to create an object for writing to a file?

PrintWriter

Write only the code that creates a file called "programming output.txt" that is ready to be written to

PrintWriter.outputFile = new PrintWriter("programmingOut.put.txt"); outputFile.println("writing");

What common class is necessary to create an object that will read the content of a file rather than input from the keyboard buffer

Scanner Scanner inputFile = newScanner(file) (Scanner, the Scanner class)

Given the following two-dimensional array declaration which statement is true int [][] numbers= new int[6] [9];

The array numbers has 6 rows and 9 columns

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

This is an infinite loop

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

t/f A PrintWriter object is necessary if a FileWriter object is being used to work with a file

True

What character (or set of characters) is used to print a backlash (\) in a string literal?

\\

What will be returned from the following method public static float[] getValue(int x) { /* Method code */ }

a reference to an array of float values

For the following code, what would be the value of str[2] String[] str={"abc", "def", "ghi", "jkl"};

a reference to the String "ghi"

In all but rare cases, loops must contain within themselves:

a way to terminate

What would be the results of the following code int[]x={55,33,8,,22,99,11,44,66,77}; int a = 10; if(x[2] > x[5]) a = 5; else a=8;

a=5

This ArrayList class method is used to insert an item into an ArrayList

add

What would be the results after the following code was executed? int [] x = {23, 55, 83, 19}; int [] y = {36, 78, 12, 24}; x = y; y= x;

x[]={36,78,12,24} and y [] = {36,78,12,24}

t/f In the for loop, the control variable cannot be initialized to a constant value and tested against a constant value.

false

t/f The do-while loop is a pre-test loop.

false

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

for loop

If numbers is a two-dimensional int array that has been initialized and total is an int that has been set to 0, which of the following will sum all the elements in the array?

for(int row = 0; row < numbers.length; row++) { for(int col = 0; col < numbers[row].length; col++) total += numbers[row][col]; }

What package needs to be imported in order to create a file for java to write to?

import java.io*;

When using the PrintWriter class, which of the following import statements would you write near the top of your program?

import java.io*;

This method is used to close both file reading and file writing objects to release memory back to RAM

inputFile.close();

A sentinel value __ and signals that there are no more values to be entered

is a special value that cannot be mistaken as a member of the list

Name the three output methods that may be used with the output file object to write code to a file

outputFile.println(""); outputfile.print(""); outputfile.printf("");

Which of the following is a correct method header for receiving a two-dimensional array as an argument

public static void passArray(int [][] intArray)

You can use this ArrayList class method to replace an item at a specific location in an ArrayList

set?

You use this method to determine the number of items stored in an ArrayList object

size

Given that String[] str has been initialized, to get a copy of str[0] with all characters converted to upper case, use the following statement:

str[0].tooUpperCase();

A __ file is the preferable file type for storing files for processing with the file extension __

text, .txt

In order to do a binary search on an array

the array must first be sorted in ascending order

When an individual element of an array is passed to a method

the method does not have direct access to the original array

What two programming words should be written after the main method header(immediately to the right) to prevent an error in compiling code with file manipulation?

throws IOException

t/f A sorting algorithm is a technique for scanning through an array and rearranging its contents in some specific order

true

t/f An ArrayList object automatically expands in size to accommodate the items stored in it.

true

t/f Any items typed on the command-line, separated by space, after the name of the class are considered to be one or more arguments that are to be passed into the main method

true

t/f Java provides a set of simple unary operators designed just for incrementing and decrementing variables.

true

t/f The PrintWriter object erases an exiting file and rewrites it every time an execution is run

true

t/f To compare the contents of two arrays, you must compare the elements of the two arrays

true

t/f When an array of objects is declared, but not initialized, the array values are set to null

true

What will be the values of x and y as a results of the following code? int x = 12, y = 5; x += y--;

x = 17, y = 4

What would be the results after the following code was executed? int [] x={23,55,83,19}; int[]y={36,78,12,24}; for(int a=0; a<x.length; a++) { x[a] = y[a]; y[a]=x[a]; }

x[]={23,55,83,19} and y[] = {36,78,12,24}


Kaugnay na mga set ng pag-aaral

Unit3 + Unit 4: Finance and Credit Laws

View Set

unit 7: FDR New Deal and Response to Great Depression

View Set

Chapter 7 MC2 Review - Computer Programming

View Set

6.1 Speaking Test ~ Wednesday, January 25th

View Set

Logical Fallacies Test 3/20/18 YOU CAN DO IT!!!!!!

View Set

Google Analytics Individual Qualification Exam Answers 2020 (1)

View Set