Send a link to your students to track their progress
81 Terms
1
New cards
2
New cards
If method A calls method B, and method B calls method C, and method C calls method D, when method D finishes, what happens?
control is returned method
3
New cards
The process of breaking a problem down into smaller pieces is sometimes called __________.
the divide and computer method
4
New cards
Which type of method performs a task and sends a value back to the code that called it?
value returning
5
New cards
When you pass an argument to a method you should be sure that the argument's type is compatible with ________
the parameter variable data type
6
New cards
Methods are commonly used to:
Break a problem down into small manageable pieces
7
New cards
Given the following method, which of these method calls is **correct**?
public static void showProduct (int num1, double num2)
{
int product;
product = num1 \* (int)num2;
System.out.println("The product is " + product);
}
showProduct(…)
8
New cards
\ Given the following method header, which of these method calls is **incorrect**?
\ public void displayValue(int x, int y)
displayValue(a,b);// where a is a long and b is an int
9
New cards
\ A __________ type of method performs a task and then terminates.
void
10
New cards
Assume that the following method header is for a method in class A.
public void displayValue(int value)
Assume that the following code segments appear in another method, also in class A. Which contains a **correct** **call** to the displayValue method?
int x = 7;
dsiplayValue(x);
11
New cards
\ A __________ is a part of a method that contains a collection of statements that are performed when the method is executed.
method body
12
New cards
What value will be returned from the following method?
public static int methodA()
{
double a = 3.5 + 4.5;
return a;
}
nothing, the code ha san error
13
New cards
\ Which of the following is *not* a part of a method call?
return type
14
New cards
What value will be returned from the following method?
\ public static double methodA()
{
double a = 3.5 + 4.5;
return a;
}
8\.0
15
New cards
The lifetime of a method's local variable is __________.
only while the method is executing
16
New cards
\ A parameter variable's scope (accessibility) is confined to __________.
the method in which the parameter is declared
17
New cards
\ Values that are sent into a method are called __________.
arguments
18
New cards
In the following code, System.out.println(num) is an example of __________.
\ double num = 5.4;
System.out.println(num);
a void method
19
New cards
Local variables __________.
are only visible to the method in which they are declared
20
New cards
Given the following method, which of these method calls is **correct**?
\ public static void showProduct (double num1, int num2)
{
double product;
product = num1 \* num2;
System.out.println("The product is " + product);
}
showProduct(10.0, 4);
21
New cards
When an object, such as a String, is passed as an argument it is __________.
actually a reference to the object that is passed
22
New cards
Character literals are enclosed in \__________ and string literals are enclosed in \__________.
single quotes, double quotes
23
New cards
Which of the following is NOT a rule that must be followed when naming identifiers?
identifiers can contain space
24
New cards
What is the result of the following Java expression? 4 + 3 - 2 * 20
-33
25
New cards
What is the result of the following Java expression? 23 % 3
2
26
New cards
What is the result of the following Java expression? 25 / 10
2
27
New cards
In Java, \__________ must be declared before they can be used.
variables
28
New cards
A Java source file must be saved with the extension
.java
29
New cards
A variable of type boolean data may contain which of the following range of values?
true and false
30
New cards
Which of the following is a value that is written into the code of a program?
a literal
31
New cards
Which of the following files would contain the translated Java byte code for a program named Demo?
demo.class
32
New cards
Which of the following commands would you use to compile a program named First?
javac First.java
33
New cards
Which of the following is a named storage location in the computer's memory?
a variable
34
New cards
Variables are classified according to their
data types
35
New cards
Every Java application program must have
a method named main
36
New cards
If x has been declared a variable of type int, which of the following statements is NOT valid?
x\=2,000;
37
New cards
\ Given the following statement, which of the following expressions would be used to generate a value on a game die?
Random randomNumbers = new Random();
die = randomNumbers.nextInt(6) + 1;
38
New cards
\ Which of the following statements opens a file named MyFile.txt and allows you to append data to its existing contents?
FileWriter fwriter = new FileWriter("MyFile.txt", true); \n PrintWriter outFile = new PrintWriter(fwriter);
39
New cards
Assume that inputFile references a Scanner object that was used to open a file.
Which of the following while loops is the correct way to read data from the file until the end of the file is reached?
while (inputFile.hasNext())
40
New cards
\ Which of the following is the method you can use to determine whether a file exists?
the File class's exists method
41
New cards
Given the following statement, which statement will write "Calvin" to the file DiskFile.txt? \n \n PrintWriter diskOut = new PrintWriter("DiskFile.txt"); \n \n -System.out.println(diskOut, "Calvin"); \n -DiskFile.println("Calvin"); \n -PrintWriter.println("Calvin"); \n -diskOut.println("Calvin");
diskOut.println("Calvin");
42
New cards
\ Given the following statement, which of the following expressions will generate a random number in the range of 1 through 10?
Random randomNumbers = new Random();
myNumber = randomNumbers.nextInt(10) + 1;
43
New cards
\ Which of the following statements opens a file named MyFile.txt and allows you to read data from it?
File file = new File("MyFile.txt"); \n Scanner inputFile = new Scanner(file);
44
New cards
\ When working with the PrintWriter class, which of the following import statements should you have near the top of your program?
import java.io.\*;
45
New cards
Assuming that inputFile references a Scanner object that was used to open a file, which of the following statements will read an int from the file?
int number = inputFile.readInt();
46
New cards
\ Which of the following statements will create an object from the Random class?
Random myNumber = new Random();
47
New cards
\ A(n) __________ is used as an index to pinpoint a specific element within an array.
subscript
48
New cards
\ What would be the result after the following code is executed?
What will be the result after the following code is executed?
final int ARRAY_SIZE = 5;
double\[\] x = new double\[ARRAY_SIZE\];
for (int i = 1; i < ARRAY_SIZE; i++)
{
x\[i\] = 10.0;
}
all values in the array except the first will be initialized to 10.0
50
New cards
What will be the value of x\[8\] after the following code is 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
51
New cards
15\. What would be the result after the following code is executed?
final int SIZE = 25;
int\[\] ages = new int\[SIZE\];
... // Code that will put values in array
int value = 0;
for (int i = 0; i < ages.length; i++)
{
value += ages\[i\];
}
value contains the sum of all values in array ages
52
New cards
For the following code, what would be the value of str\[2\]?
String\[\] str = {"abc", "def", "ghi", "jkl"};
a reference to the string object “ghi”
53
New cards
\ When an ***individual element*** of an array is passed to a method __________.
none are true
54
New cards
\ In memory, an array of String objects __________.
consists of an array of references to String objects
55
New cards
\ Java performs ____________, which means that it does not allow a statement to use a subscript that is outside the range of valid subscripts for the array.
array bounds checking
56
New cards
\ \ Given that String\[\] str has been initialized, to get a copy of str\[0\] with all the characters converted to uppercase, you would use the __________ statement.
str.\[0\].toUpperCase());
57
New cards
\ What would be the result after the following code is 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\];
}
`{36, 78, 12, 24}` and `y` will contain the values `{23, 55, 83, 19}`.
58
New cards
\ What will be the results after the following code is executed?
int\[\] ages = new int\[25\];
... // Code that will put values in ages
int value = ages\[0\];
for (int a = 1; a < ages.length; a++)
{
if (ages\[a\] > value)
value = ages\[a\];
}
value contains the highest value in ages
59
New cards
The __________ indicates the number of elements the array can hold
array’s size
60
New cards
What will be the results after the following code is executed?