Exam 1 Study Guide (a)

¡Supera tus tareas y exámenes ahora con Quizwiz!

What is output? java MyProgram file1.txt public class MyProgram{ public static void main(String[] args){ System.out.println(args[0]); } } A). java B). MyProgram C). file1.txt D). Error: array index out of bounds

C). file1.txt

What is output? (_ represents a blank space) A). Her name is ___Sam B). Her name is %6.3s C). Her name is Sam D). her name is Samant

A). Her name is ___Sam

The ArrayList class is in the ________ package. A). java.util B). java.lang C). java.arraylist D). java.array

A). java.util

Subscripting (indices) always starts with ________. A). -1 B). 0 C). 1 D). none of these

B). 0

The ________ method removes an item from an ArrayList at a specific index. A). pop B). remove C). clear D). deleteAt

B). remove

For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"}; A). a reference to the String object containing "def" B). "def" C). "ghi" D). a reference to the String object containing "ghi"

D). a reference to the String object containing "ghi"

In memory, an array of String objects ________. A). is compressed to four bytes for each element B). consists of elements, each of which is a reference to a String object C). must be initialized when the array is declared D). consists of an array of references to String objects

D). consists of an array of references to String objects

T or F: When an array of objects is declared but not initialized, the array values are set to 0.

F

What does the following statement do? double[] array1 = new double[10]; A). It declares array1 to be a reference to an array of double values. B). It does all of these. C). It creates an instance of an array of ten double values. D). It will allow valid subscripts in the range of 0 through 9.

B). It does all of these.

What is output? double pi = 3.14159; System.out.printf("The value of PI is -%4.3f", pi); A). The value of PI is -%4.3f B). The value of PI is -3.142 C). The value of PI is 0003.142 D). The value of PI is 3.14159

B). The value of PI is -3.142

You can use the ________ method to replace an item at a specific location in an ArrayList. A). remove B). replace C). add D). set

D). set

T or F: An ArrayList object automatically expands in size to accommodate the items stored in it.

T

T or F: Arrays class is in Java.Util package.

T

Which line(s) immediately flush the output buffer? A). System.out.print("One for the money"); B). System.out.print("Two for the show\n"); C). System.out.println("Three to get ready"); D). System.out.print("And four to go"); E). System.out.flush();

lines 2, 3 and 5

It is common practice to use a ________ variable as a size declarator. A). reference B). static C). boolean D). final

D). final

If any int array, a, is passed as a parameter to a method, which of the following would adequately define the parameter list for the method header? A). (int[]) B). (int a) C). (int[] a) D). (int a[]) E). (a[])

C). (int[] a)

When an individual element of an array is passed to a method ________. A). the method does not have access to the original array B). a reference to the array is passed C). it is passed like any other variable D). All of these are true.

A). the method does not have access to the original array

Which of the following for loops is valid, given the following declaration? String[] names = {"abc", "def", "ghi", "jkl"}; A). for (int i = 0; i < names.length; i++) System.out.println(names[i].length); B). for (int i = 0; i < names.length; i++) System.out.println(names[i].length()); C). for (int i = 0; i < names.length(); i++) System.out.println(names[i].length); D).for (int i = 0; i < names.length(); i++) System.out.println(names[i].length());

B). for (int i = 0; i < names.length; i++) System.out.println(names[i].length());

What is the error in readFile()? public void readFile(){ FileInputStream fbStream = null; Scanner inFS = null; int value = 0; fbStream = new FileInputStream("data.txt"); inFS = new Scanner(fbStream); value = inFS.nextInt(); System.out.println("Value: " + value); fbStream.close(); } A). There is a data input mismatch B). readFile( ) does not throw IOException C). inFS is not closed D). The code has no errors

B). readFile( ) does not throw IOException

Which XXX completes the code to read every integer from file "data.txt"? FileInputStream inputStream = null; Scanner inFS = null; int total = 0; inputStream = new FileInputStream("data.txt"); inFS = new Scanner(fileByteStream); while(XXX){ total = total + inFS.nextInt(); } System.out.println("Total: " + total); A). inputStream.hasNextInt( ) B). total != 0 C). inFS.hasNextInt( ) D). inFS.eof( ) == false

C). inFS.hasNextInt( )

When an array is passed to a method ________. A). the method has direct access to the original array B). it is passed just as any other object would be passed C). a reference to the array is passed D). All of these are true

D). All of these are true

Which of the following statements is(are) true about this code? final int ARRAY_SIZE = 10;long[] array1 = new long[ARRAY_SIZE]; A). It will allow valid subscripts in the range of 0 through 9. B). It creates an instance of an array of ten long values. C). It declares array1 to be a reference to an array of long values. D). All of these are true.

D). All of these are true.

Which statement is true? A). Command-line arguments are stored as an array of integers B). The value 24 could not be entered as a command-line argument since it is a number C). program typically crashes if the user provides too many command-line arguments D). Command-line arguments are stored as an array of Strings

D). Command-line arguments are stored as an array of Strings

Which is true? A). A program must import java.io.system to use System.out B). System.output.print() only outputs objects of type String C). The output of println() for an object reference includes all data stored in the object D). Data written to System.out are placed in a buffer and eventually output

D). Data written to System.out are placed in a buffer and eventually output

What is output given the user input? Input: three blind mice System.out.print("Enter info: "); Scanner keyboard = new Scanner(System.in); String info = keyboard.nextLine(); Scanner inputScnr = new Scanner(info); int item1 = inputScnr.nextInt(); String item2 = inputScnr.next(); String item3 = inputScnr.next(); System.out.println(item1 + " " + item2 + " " + item1); A). mice blind three B). three blind mice C). three three three D). Error: input mismatch exception

D). Error: input mismatch exception

What will be the results after the following code is executed? int[] x = { 55, 33, 88, 22, 99, 11, 44, 66, 77 }; int a = 10; if(x[2] > x[5]) a = 5; else a = 8; A). a = 8 B). a = 13 C). a = 10 D). a = 5

D). a = 5

If a and b are both int arrays, then a = b will A). copy all elements of a into b B). return true if each corresponding element of b is equal to each corresponding element of a (that is, if a[0] is equal to b[0], a[1] is equal to b[1] and so forth) and return false otherwise C). return true if a and b are aliases and return false otherwise D). create an alias E). copy the zero element of b into the zero element of a

D). create an alias The = is an assignment operator. If the two variables are primitives, than the left-hand variable gets a copy of the right-hand variable. However, since a and b are arrays, the reference variable a is set to the reference variable b, resulting in both a and b referencing the same array in memory, or they are now aliases of each other.

Select the statement in main() to assign a command-line argument to String lastName. java AddInfo John Smith 65 Physician A). lastName = "Smith"; B). lastName = args; C). lastName = args[3]; D). lastName = args[1]

D). lastName = args[1]

Each array in Java has a public field named ________ that contains the number of elements in the array. A). capacity B). size C). limit D). length

D). length

Which XXX allows information to be written to a file using print( )? FileOutputStream foStream = null; PrintWriter outFS = null; foStream = new FileOutputStream("outfile.txt"); XXXoutFS.println("Java is my favorite language!"); A). outFS = new PrintWriter("outfile.txt"); B). new PrintWriter(foStream); C). outFS = PrintWriter.open(foStream); D). outFS = new PrintWriter(foStream);

D). outFS = new PrintWriter(foStream);

Which of the following is a correct method header for receiving a one-dimensional array as an argument? A). public static void passMyArray(int[1, 2]) B). public static void passMyArray(int[],int[] myArray) C). public static void passMyArray[1]) D). public static void passMyArray(int[] myArray)

D). public static void passMyArray(int[] myArray)

Which XXX is needed for enterNumber() to read a value from standard input? public int enterNumber() XXX{ int value; value = System.in.read(); return value; } A). import java.io B). throws SystemException C). nothing is needed D). throws IOException

D). throws IOException


Conjuntos de estudio relacionados

PN Adult Medical Surgical Online Practice 2023 B

View Set

HPE 101 Chapter 8 Addictions/ Drug Abuse

View Set

CHAPTER TWO FINANCIAL MANAGEMENT

View Set

Mobility, Neuromuscular Disorder peds

View Set

Chapter 3 Principles of Macroeconimics

View Set

BUSI 2301 Business Law Exam One Ch 1 - 15, Test 1 Chapters 1-3 Business Law Today (Intro to business law), Business Law Today, Business Law Final Exam Study Guide, Business Law Today - The Essentials Midterm, Business Law Today, The Essentials - Fina...

View Set

Chapter 9: Helath and Disability Income Insurance

View Set

Chapter 30: Abdominal and Genitourinary Injuries

View Set

retirement, Rec - Retirement (5)

View Set