CS1440 Final Exam Review

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

memory addresses

When you use the '==' operator with reference variables, the operator compares the _____ that the variables contain.

73

Which element is at [2][1]?

public int[] getArray()

Which method header indicates that the method returns an array? Select one: public int getArray() public int[] getArray() public void getArray(int[] a) public [int] getArray()

public void setArray(int[] a)

Which method header indicates that the method takes an array as a parameter? Select one: public void setArray(int a) public int[] setArray() public void setArray([int] a) public void setArray(int[] a)

single quotes; double quotes

Character literals are enclosed in ________; string literals are enclosed in ________.

False

Converting a double to an int would be a widening conversion.

using the private access specifier on the class fields

Data hiding, which means that critical data stored inside the object is protected from code outside the object is accomplished in Java by

boolean flag = false;

Declare a boolean named flag and initialize it to false (don't forget the semi-colon).

machine

Each different type of CPU has its own __________ language.

iteration

Each repetition of a loop is known as a(n) _____.

String

For each string literal that appears in a Java program, a __________ object is created in memory to hold it.

right, closing

For every left brace, or opening brace, there must be a corresponding _________ brace, or ________ brace.

str[0].toUpperCase();

Given that String[] strhas been initialized, to get a copy ofstr[0]with all characters converted to upper case, use the following statement: Select one: str[0].upperCase(); str.toUpperCase(); str.uppercase(); str[0].toUpperCase();

3

How many errors are there in the following program? public class Foo { public static void main(String[] args) { Systemout.println("Something is wrong") } {

2

How many format specifiers are in the following line of code? System.out.printf("The temperatures are %f and %f degrees.\n", temp1, temp2);

.3

I want the following line of code to print out the temperature with 3 decimal places. System.out.printf("The temperature is %______f.", temp);

name.equals(otherName);

I want to know if two strings, name and otherName, are equal. Which option below will accomplish this?

object

If you write a toString method for a class, Java will automatically call the method when the _____ is passed as an argument to print or println.

Unicode character code

In Java, when a character is stored in memory, it is actually as a(n) ________.

+

In UML diagrams, this symbol indicates that a member is public.

String

Java implicitly calls an object's toString method any time you concatenate an object of the class with a(n) _____.

False

Java syntax requires that variable names begin with a lower-case letter.

True

(True or False) A break statement can be used to terminate a loop.

True

(True or False) A class is not an object, but a description of an object.

True

(True or False) A local variable's scope always ends at the closing brace of the block of code in which it is declared.

False

(True or False) A loop that repeats a specific number of times is known as a conditional loop.

True

(True or False) A sentinel value is a special value that cannot be mistaken as a member of the list and signals that there are no more values to be entered.

False

(True or False) All Scanner methods return Strings.

True

(True or False) All format specifiers must end with a conversion character, such as f for floating-point value, or d for decimal integer.

True

(True or False) An array is an object that can store a group of values, all of the same type.

the String

Names is an array of strings. Will names[3].length() return the length of the String at index 3 or the length of the names array

False

Scanner keyboard = new Scanner(System.in); Scanner output = keyboard; (True or False) After running the two lines of code above, two Scanner objects will have been created.

semicolons

Statements are terminated with ____________.

java.util

The ArrayList class is in this package. Select one: java.lang java.arraylist java.util java.array

True

(True or False) An important style rule you should adopt for writing if statements is to write the conditionally executed statement on the line after the if statement.

True

(True or False) Class-type variables hold the memory address of the data the item is associated with. If a variable is of the type String, it is a class-type variable.

True

(True or False) Each Scanner class method in this chapter waits for the user to press the enter key before it returns a value.

True

(True or False) Every class automatically has a toString method.

True

(True or False) I can check if two Strings are equal, using compareTo.

False

(True or False) Identifiers make up the core of Java and each has a specific purpose.

True

(True or False) If a partially filled array is passed to a method, the variable that holds the count of items in the array must also be passed as an argument.

True

(True or False) If a random object is instantiated with 'new Random()', the random object will produce the same sequence of random numbers every time the program is executed.

False

(True or False) If a[] and b[] are two integer arrays, the expression a == b compares the array contents.

False

(True or False) In Java, all arguments of the primitive data types are passed by reference, which means that the argument itself is passed into a parameter variable.

False

(True or False) In Java, the word Public and public are the same thing.

False

(True or False) In a for loop, the control variable can only be incremented.

False

(True or False) In situations where a mathematical expression has one or more values of the double, float, or long data types, Java strives to convert all of the operands in the expression to the long data type.

False

(True or False) In the for loop, the control variable cannot be initialized to a constant value and tested against a constant value.

True

(True or False) It is not necessary to create an object to call a static method.

True

(True or False) It is not required that the name of main's parameter array be args.

True

(True or False) It is possible to create a field or method that does not belong to any instance of a class.

True

(True or False) It is the standard Java practice that class names begin with a capital letter.

False

(True or False) Java automatically initializes array elements to -1.

True

(True or False) Java does not limit the number of dimensions that an array may have.

False

(True or False) Once an ArrayList is created, it cannot change size.

True

(True or False) Scanner methods the return numeric data (nextDouble(), nextInt(), etc.) may not read all the characters typed in by the user.

False

(True or False) String is one of Java's primitive data types.

True

(True or False) The Java API has one package, java.lang, hat is automatically imported into every Java program. This package contains String and System.

False

(True or False) The action "Wear a coat" is always executed in the above decision structure.

False

(True or False) The arguments are passed to the parameter variables opposite to the order in which they appear in the method call.

True

(True or False) The compiler doesn't care about the style of your code as long as it is syntactically correct.

False

(True or False) The continue keyword can be used to terminate a loop.

True

(True or False) The do-while loop must be terminated with a semicolon.

True

(True or False) The following code will not compile or run. final int PARTICIPANTS; PARTICIPANTS = 100; System.out.print(PARTICIPANTS); PARTICIPANTS = 120;

True

(True or False) The following two lines of code cause the same result to be stored in x: x = x + 6; and x += 6;

True

(True or False) The if/else statement will execute one group of statements if its boolean expression is true or another group if its boolean expression is false.

False

(True or False) The only time Java provides a default constructor is when you write your own constructor for a class.

True

(True or False) The println method advances the cursor to the next line after its message is displayed, while the print method does not.

False

(True or False) The variable that is used to accumulate a running total in a loop is called a sentinel value.

True

(True or False) To allow a method to rethrow an exception that has not been dealt with, you simply write a throws clause in the method header.

True

(True or False) Two arrays cannot be equal if they have different lengths.

False

(True or False) When a local variable in an instance method has the same name as an instance field, the instance field hides the local variable.

True

(True or False) When an array of objects is declared, but not initialized, the array values are set to null.

True

(True or False) When an object is passed as an argument, it is actually a reference to the object that is passed.

True

(True or False) When an object reference is passed to a method, the method may change the values in the object.

True

(True or False) When testing for character values, the switch statement does not test for the case of the character.

False

(True or False) When two Strings are compared using the compareTo method, the cases of the two strings are not considered.

False

(True or False) When you create an array of objects, the objects are initialized to "blank" versions of the object (an object with it's fields initialized to default values).

True

(True or False) When you declare a variable inside of a loop, it only exists in that loop. You cannot access the variable outside of the loop.

True

(True or False) When you use the compareTo method to compare two strings, the strings are compared character by character.

True

(True or False) You can check if a file exists using the exists method in the File class.

False

(True or False) You can compare two arrays with '=='.

True

(True or False) You can create String objects with the new operator and initialize the object by passing a string literal to the constructor.

False

(True or False) You can force an integer literal to be treated as a long by suffixing it with the letter T.

True

(True or False) You can have multiple methods with the same name, as long as they use different parameters.

True

(True or False) You can overload constructors the same way you can overload methods. You just need to have a different method signature.

False

(True or False) You can use the hasNext method in the FileWriter class to detect the end of a file.

True

(True or False) You can write a method to accent a variable number of object references as arguments.

java.util.Random

The Random class is imported from _____.

+

The String concatenation operator is _____.

PrintWriter

The _____ class allows you to open a file for writing.

if

The ________ statement is used to make simple decisions in Java.

3

The array above is named arr. What is returned by arr.length?

programmed

The computer can do a wide variety of tasks because it can be ______________.

posttest

The do-while loop is a _______ loop.

twice

The double data type uses _______ as much memory as the float data type.

False

The following code will display the number 5 to the screen. public static void main(String[] args) { int value = 5; System.out.println(Value); }

Hello world!

The following line of code displays a message on the screen. What message is displayed? System.out.println("Hello world!");

flag

A _______ is a boolean variable that signals when some condition exists in the program.

control

A loop is a _____ structure that causes a statement or group of statements to repeat.

running total

This is a sum of numbers that accumulates with each iteration of a loop.

do-while loop

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

application software

This type of software refers to programs that make the computer useful to the user.

arrays

A two-dimensional array is actually an array of ____.

constructor

A(n) __________ is a method that is automatically called when an instance of a class is created.

rows, columns

To declare a two-dimensional array, two sets of brackets and two size declarators are required: The first one is for the number of _____ and the second one is for the number of _____.

\n

To display the output on the next line, you can use the println method or use this escape sequence in the print method.

System.out.println("Hello, world");

To print "Hello, world" on the monitor, use the following Java statement

\t

To represent the tab character in a Java String, a programmer enters _____.

local variables

Variables that are declared inside a method are called what?

parameter

Variables that are declared inside the parentheses of a method header are know as ___________ variables.

void

What Java keyword indicates that a method returns no data to the statement that called it?

nextLine()

What Scanner class method reads a String?

nextInt()

What Scanner class method reads an int?

120

What will be the value of ans after the following code has been executed? int x = 65; int y = 55; if (x >= y) int ans = x + y;

20

What will be the value of ans after the following code has been executed? int x = 90, y = 55, ans = 10; if ( x == y); ans *= 2;

15

What will be the value of x after the following code is executed? int x = 75; int y = 60; if (x > y) x = x - y;

33

What will be the value of x[1] after the following code is executed? int[] x = {22, 33, 44}; arrayProcess(x[1]); ... public static void arrayProcess(int a) { a = a + 5; }

180

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; }

There are 5785 hens in the hen house.

What would be displayed as a result of the following code? int x = 578; System.out.print("There are " + x + 5 + " " +"hens in the hen house.");

The program will crash.

What would be the output of the following code? int[] values = new int[5]; for (int count = 1; count <= 5; count++) values[count] = count + 1; for (int count = 1; count <= 5; count++) System.out.print(values[count]);

a = 5

What would be the results of the following code? 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 reference to an object of that class

When a method's return type is a class, what is actually returned to the calling program?

object

When an entire array is passed into a method, it is passed just as a(n) _____ is passed.

value = 10;

Which of the following statements declare an int variable, name it "value", and initialize it to 10?

float[] scores = new float[50];

Write a statement that creates a 50-element float array referenced by the variable scores.

Scanner

You can use the _____ class to read input from a file.

FileWriter

You can use the ______ class to append data to an existing file.

1

You should use the do-while loop when you want to make sure the loop executes at least _______ time(s).

diamond

You show aggregation in a UML diagram by connecting two classes with a line with an open _______ at one end.

import

You use the _________ key word to import a class.

input validation

_____ is the process of inspecting data given to a program by the user and determining if it is valid.

Hardware

_______________ refers to the physical components of which a computer is made.

True

if(hours > 40) { overtime = true; } else { overtime = false; } (True or False) The if-else statement above sets overtime to false if hours is less than (or equal to) 40.

True

int number = 5; number = -number; (True or False) After these two lines of code, the value stored in number is -5.

True

int[] numbers = new int[10]; for(int i = 0; i < 10; i++) { numbers[i] = 5; } System.out.print(numbers[10]); (True or False) The above code will cause an ArrayIndexOutOfBoundsException.

numbers[4] = 4;

int[] numbers = new int[5]; How would I assign the value 4 to the last spot in the array?

False

Both character literals and string literals can be assigned to a char variable.

makes the value left-justified

Adding the "-" symbol to the format specifier does what?

d. keyboard references a Scanner object.

After executing the following statement: Scanner keyboard = new Scanner(System.in); Which of the following statements is true? a. System.in references a Scanner object. b. new references a Scanner object. c. Scanner references a Scanner object. d. keyboard references a Scanner object.

references

An array of String objects is really an array of _____.

backslash

An escape sequence starts with the __________ character and is followed by one or more control characters.

System.out.printf("%-10.3f", number);

Assume the following variable declaration exists in a program: double number = 45676.23455; Write a statement that uses System.out.printf to display the value of the number variable in a field that is 10 spaces wide, rounded to 3 decimal places, and left justified. *Don't forget the semi-colon* *Don't add any words to be displayed around the variable - your answer should only display the variable with the specifications above.*

y = (short) x;

Assume x is an int and y is a short. Write a statement that will allow me to assign the value of x to the variable y without a compiler error (don't forget the semi-colon).

False

Assuming that pay has been declared a double, the following statement is valid: pay = 2,583.44;

5.0

Assuming x is a double variable, what is the result of the following expression? x = 3 / 2 + 4.0;

0-14

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

True

If x is type double, the following is a legal Java statement. x = 1;

False

If x is type int, the following is a legal Java statement. x = 1.0;

1

If x is type int, what would be stored in x after the following statement? x = (int) 1.0;

terminate

If you attempt to perform an operation with a null reference variable, the program will ______.

solution += x;

The following two lines appear in a program: Line 1: int x = 5; Line 2: double solution = 20; Line 3: solution = solution + x; I can shorten line 3 by using a combined assignment operator. What is the correct way to shorten line 3?

has a

The term for the relationship created by object aggregation is

a has a relationship

The whole-part relationship created by object aggregation is more often called

add

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

fetch instructions, follow instructions, and produce some resulting data

What is the CPU's job?

7

What is the maximum index the following array? double[] arr = new double[8];

0

What is the minimum index the following array? double[] arr = new double[8];

short

What is the type of the following variable? short temp;

2.0

What value is stored in pizzaPerPerson after the following code is executed? double pizzaPerPerson = (double) (5 / 2);

1.0

What value will be stored in temp after the following line of code? double temp = 3 / 2;

12

What value will be stored in x after the following three lines of code execute? int y = 50; int z = 4; double x = y / z;

true and false

What values can a boolean variable hold?

I am enjoying this class. I AM ENJOYING THIS CLASS. i am enjoying this class. Character at index x = n msg has 25 characters.

What will be displayed as a result of executing the following code? int x = 6; String msg = "I am enjoying this class."; String msg1 = msg.toUpperCase(); String msg2 = msg.toLowerCase(); char ltr = msg.charAt(x); int strSize = msg.length();System.out.println(msg); System.out.println(msg1); System.out.println(msg2); System.out.println("Character at index x = " +ltr); System.out.println("msg has " + strSize +"characters.");

int

What will be the data type of z? byte x = 3; byte y = 9; _____ z = x + y;

There will be a compilation error.

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; }


Set pelajaran terkait

mass communication- Audio; Radio and Podcast

View Set

Chapter 11 Testbank: Respiratory & Lungs

View Set

Clinical Procedures: Chapter 34 & 35

View Set