CH 5

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

!The header of a value-returning method must specify ______ a. The method's local variable names b. The name of the variable in the calling program that will receive the returned value c. The data type of the return value d. All of the above

c

The while loop has two important parts: (1) a boolean expression that is tested for a true or false value, and (2) a statement or block of statements that is repeated as long as the expression is true. T/F

T

Given the following statement, which statement will write the string "Calvin" to the file DiskFile.txt? a diskOut.println("Calvin"); b DiskFileOut.Println("Calvin"); c FileOut.Println("Calvin");

a

If you attempt to use a local variable before it has been given a value, Select one: a. a compiler error will occur b. the local variable will always contain the value 0 c. the results will be unpredictable d. the local variable will be ignored

a

In all but rare cases, loops must contain within themselves a a way to terminate b statements c increasement

a

In general, there are two types of files: a text and binary b english and spanish c binary and moniry d text and pdf

a

Given an integer variable timer, write a statement that uses the auto-decrement operator to decrease the value of that variable by 1. a --timer b timer--

b

The ________ loop is ideal in situations where you always want the loop to iterate at least once. a for b do while c while d if

b

This type of loop will always be executed at least once. a pretest b post test

b

Which of the following is not part of a method call? Select one: a. method name b. return type c. parentheses d. all of the above are part of a method call

b

` This type of method does not return a value a null b void c empty d anonymous

b

`The do-while loop is this type of loop a pretest b posttest c prefix d postfix

b

`this type of loop always executes at least once. a while b do-while c for d any of these

b

! 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; } a 130 b 110 c 210 d 90

c

! When an argument is passed to a method _____ a its value is copied into the methods parameter variable b its value may be changed within the called method c both a and b are correct d neither nor are correct

c

!A method a must have at least two parameter variables b never has parameter variables c may have zero or more parameters d may not have only one parameter variable

c

!The phrase divide and conquer is sometimes used to describe Select one: a. the backbone of the scientific method b. the process of dividing functions c. the process of breaking a problem down into smaller pieces d. the process of using division to solve a mathematical problem

c

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

c

! When the continue statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration. T/F

T

!The do-while loop must be terminated with a semicolon. T/F

T

What will be the value of x and y after the following code is executed? int x, x-12, y=5 x+=y-- a x = 17 y = 4 b x = 18 y =5 c x = 17 y = 5

a

What will be the values of x and y as a result of the following code? int x = 25, y = 8;x += y++; a x=33 y=9 b x=33 y=8 c x = 25, y=8 d x=8 y =25

a

What will the value of x after the following code is executed int x, y-15; x=y--; a 15 b17 c5 d7

a

When you pass an argument to a method, be sure that the argument's data type is compatible with: Select one: a. the parameter variable's data type b. the method's return type c. the version of Java currently being used d. IEEE standards

a

`What will the println statement in the following program segment display? int x=5 System.out.println(++x); a 5 b 6 c 0 d none of these

6

! When the break statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration. T/F

F

!In the method header, the method modifier public means that the method belongs to the class, not a specific object. T/F

F

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

F

In the method header the static method modifier means the method is available to code outside the class. Select one: True False

F

Only constants and variables may be passed as arguments to methods. Select one: True False

F

The while loop is always the best choice in situations where the exact number of iterations is known. T/F

F

!In a for loop, the control variable is always incremented. T/F

F

!Any method that calls a method with a throws clause in its header must either handle the potential exception or have the same throws clause. T/F

T

!Methods are commonly used to break a problem into small manageable pieces. Select one: True False

T

!The do-while loop is ideal in situations where you always want the loop to iterate at least once. T/F

T

!Two general categories of methods are void methods and value returning methods. Select one: True False

T

!You must have a return statement in a value-returning method. Select one: True False

T

A parameter variable's scope is the method in which the parameter is declared. Select one: True False

T

A value-returning method can return a reference to a non-primitive type. Select one: True False

T

Constants, variables, and the values of expressions may be passed as arguments to a method. Select one: True False

T

No statement outside the method in which a parameter variable is declared can access the parameter by its name. Select one: True False

T

The expression in a return statement can be any expression that has a value. Select one: True False

T

Consider this code: "int s = 20; int t = s++ + --s;". What are the values of s and t? a s= 20 t =20 b s=20 t ?

b

!If a loop does not contain, within itself, a valid way to terminate, it is called a(n) ________ loop a infinite b do-while c while d for

a

!What will be returned from the following method? public double methodA() { double a = 8.5 + 9.5; return a; } Select one: a. 18.0 b. 18 (as an integer) c. 8 d. This is an error

a

!What will be the value of x after the following code is executed? int x, y = 15;x = y--; a 15 b 16 c 0 d 14

a

!When an object, such as a String, is passed as an argument, it is Select one: a. actually a reference to the object that is passed b. passed by value like any other parameter value c. encrypted d. necessary to know exactly how long the string is when writing the program

a

'A variable that receives a value that is passed into a method is known as a(n).... a parameter b argument c signal d return value

a

A ________ loop will always be executed at least once. a posttest b pretest c suffix

a

A parameter variable's scope is: Select one: a. the method in which the parameter is declared b. the class to which the method belongs c. the main method d. All of the above

a

Assume that inputFile references a Scanner object that was used to open a file. Which of the following while loops shows the correct way to read data from the file until the end of the file is reached? a while (inputFile.hasNext()) b while (hasNext) c while (inputFile) d while (has Next.inputfile())

a

Assuming that inputFile references a Scanner object that was used to open a file, which of the following statements will read an intfrom the file? a int number = inputFile.nextInt(); b inputFile.nextint()= number

a

Consider this code: "int v = 20; --v; System.out.println(v++);". What value is printed, what value is v left with? a 19 is printed, v ends up with 20 b c d

a

In the following code, Integer.parseInt(str), is an example of ________. int num; string str = "555"; num = Integer.parseInt(str) + 5; Select one: a. a value-returning method b. a void method c. a local variable d. a complex method

a

In the header, the method name is always followed by this: Select one: a. parentheses b. return type c. data type d. braces

a

Suppose a reference variable of type File called myFile has already been declared . Create an object of type File with the initial file name input.dat and assign it to the reference variable myFile. a myFile=new File ("input.data"); b new File = myFile("input.data"); c myFile= new File("input.data")

a

This type of method performs a task and sends a value back to the code that called it. Select one: a. value-returning b. void c. complex d. local

a

Values stored in local variables Select one: a. are lost between calls to the method in which they are declared b. retain their values from the last call to the method in which they are declared c. may be referenced by the calling method d. may be referenced by any other method, if the method in which they are declared is a public method

a

What will be the value of x after the following code is executed? int x, y = 4, z = 6;x = (y++) * (++z); a 28 b 30 c 32 d 34

a

Which is a control structure that causes a statement or group of statements to repeat? a loop b statement c argument d method

a

`The body of a method is enclosed in a curly braces b square brakets c parentheses d quotation marks

a

`The for loop is this type of loop a pretest b posttest c prefix d postfix

a

`The while loop is this type of loop a pretest b posttest c prefix d postfix

a

`This expression is executed by the for loop only once, regardless of the number of iterations. a initialization expression b test expression c update expression d pre-increment expressoin

a

`This is a special value that signals when tere are no more items from a list of items to be processed. This value cannot be mistaken as an item from the list. a sentinel b flag c signal d accumulator

a

`This is a variable that controls the number of iterations performed by a loop. a loop control variable b switch c argument d method

a

`What will the println statement in the following program segment display? int x=5 System.out.println(x++); a 5 b 6 c 0 d none of these

a

which of the following are pre-test loops? a while and for b while and do while c for and if d if and while

a

! Before entering a loop to compute a running total, the program should first a read all the values into main memory b set the accumulator variable to an initial value, often zero c set all variables to zero d know exactly how many values there are to total

b

! Given the following method header, which of these method calls is INCORRECT? public void displayValue (int x, int y); a all of these would give an error b displayValue (a, b); //where a is a short and b is a long c displayValue (a,b); // where a is an int and b is a byte d displayValue (a,b); // where a is a short and b is a byte

b

!Methods are commonly used to a. speed up the compilation of a program b. break a problem down into small manageable pieces c. emphasize certain parts of the logic d. document the program

b

!The ________ loop is ideal in situations where the exact number of iterations is known. a while b for c if d do while

b

!This type of method performs a task and then terminates. Select one: a. value-returning b. void c. local d. simple

b

!Values that are sent into a method are called ____________. Select one: a. variables b. arguments c. literals d. types

b

!When an argument value is passed to a method, the receiving parameter variable is a. declared within the body of the method b. declared in the method header inside the parentheses c. declared in the calling method d. uses the declaration of the argument

b

'A value that is passed into a method when it is called is know as a(n).... a parameter b argument c signal d return value

b

'This javadoc tag is used to document a parameter variable a @parameter b @param c @paramvar d @arg

b

A loop that repeats a specific number of times is known as a(n) ________ loop. a infinite b count-controlled c for d while

b

A special variable that holds a value being passed into a method is called what? Select one: a. Modifier b. Parameter c. Alias d. Argument

b

A(n) ________ is a special value that cannot be mistaken as a member of a list of data items and signals that there are no more data items to be processed. a switch b sentinel c argument d expression

b

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 legal call to the displayValue method? Select one: a. int x = 7; void displayValue(x); b. int x = 7; displayValue(x); c. int x = 7; displayValue(int x); d. int x = 7; displayValue(x)

b

!Which of the following would be a valid method call for the following method? public static void showProduct(int num1, double num2) { int product; product = num1 * num2; System.out.println("The product is " + product); } a. showProduct("5", "40"); b. showProduct(10.0, 4.6); c. showProduct(10, 4.5); d. showProduct(3.3, 55);

c

'This type of loop ha no way of ending and repeats until the program is interrupted. a indeterminate b interminable c infinite d timeless

c

A loop that executes as long as a particular condition exists is called a(n) ________ loop a switch b for c conditional d while

c

This part of a method is a collection of statements that are performed when the method is executed. Select one: a. method header b. return type c. method body d. method modifier

c

What is wrong with the following method call? displayValue (double x); Select one: a. There is nothing wrong with the statement. b. displayValue will not accept a parameter. c. should not include the data type in the method call. d. x should be a String.

c

What will be the result of the following code? int num; string str = "555"; num = Integer.parseInt(string str) + 5; Select one: a. num will be set to 560 b. str will have a value of "560" c. the last line of code will cause an error d. neither num or str will be changed

c

What will be the value of x after the following statements are executed?int x = 10; for (int y = 5; y < 20; y +=5)x += y; a 20 b 30 c 40 d 10

c

Which of the following is included in a method call? Select one: a. return type b. method modifiers c. parentheses d. return variable

c

Which of the following would be a valid method call for the following method? public static void showProduct (int num1, double num2) { int product; product = num1 * (int)num2; System.out.println("The product is " + product); } Select one: a. showProduct(5.5, 4.0); b. showProduct(10.0, 4); c. showProduct(10, 4.5); d. showProduct(33.0, 55.0);

c

`In the expression number ++, the ++ operator is in what mode? a prefix b pretest c postfix d posttest

c

! A ______ type of method performs a task and then terminates a simples b value returning c local d void

d

!A value-returning method must specify ____ as its return type in the method header. Select one: a. an int b. a double c. a boolean d. any valid data type

d

!How many times will the following do-while loop be executed? int x = 11; do{x += 20;} while (x > 100); a 5 b 0 c 4 d 1

d

!How many times will the following for loop be executed? for (int count = 10; count <= 21; count++) System.out.println("java is great!") a 0 b 11 c 10 d 12

d

!What will be printed after the following is executed? for (int number = 5; number<= 15; number +=3) System.out.print(number + ","); a this is an invalid for statement b 5,8, 11, 14,17, c 5,6,7,8,9,10,11,12,13,14,15 d 5,8,11,14

d

!Which of the following would be a valid method call for the following method? public static void showProduct (double num1, int num2) { double product; product = num1 * num2; System.out.println("The product is " + product); } a. showProduct("5", "40"); b. showProduct(10.0, 4.6); c. showProduct(10, 4.5); d. showProduct(3.3, 55);

d

!Which type of method performs a task and sends a value back to the code that called it? a complex b void c local d value-returning

d

'Each repetition of a loop is known as a(n) ________. a repetition b loop c try d iteration

d

'The variable used to keep the running total is called a(n) a sentinel b sum c total d accumulator

d

'This appears at the beginning of a method definition a semicolon b parentheses c body d header

d

'this statement causes a method to end and sends a value back to the statement that called the method. a end b send c exit d return

d

Breaking a program down into small manageable methods Select one: a. makes problems more easily solved b. allows for code reuse c. simplifies programs d. all of the above

d

In a general sense, a method is Select one: a. a plan b. a statement inside a loop c. a comment d. a collection of statements that performs a specific task

d

Local variables Select one: a. are hidden from other methods b. may have the same name as local variables in other methods c. lose the values stored in them between calls to the method in which the variable is declared d. All of the above

d

Local variables can be initialized with Select one: a. constants b. parameter values c. the results of an arithmetic operation d. any of the above

d

The lifetime of a method's local variable is Select one: a. the duration of the program b. the duration of the class to which the method belongs c. the duration of the method that called the local variable's method d. only while the method is executing

d

What will be returned from the following method? public int methodA() { double a = 8.5 + 9.5; return a; } Select one: a. 18.0 b. 18 (as an integer) c. 8.0 d. This is an error

d

Which of the following is not a benefit derived from using methods in programming? Select one: a. problems are more easily solved b. simplifies programs c. code reuse d. all of the above are benefits

d

Which of the following is not a part of the method header? Select one: a. return type b. method name c. parentheses d. semicolon

d

Which of the following values can be passed to a method that has an int parameter variable? Select one: a. float b. double c. long d. All of the above e. None of the above

e

`A method header can contain a method modifiers b the method return type C the method name Da list of parameter declarations e all of these f none of these

e


Set pelajaran terkait

Test Review - Quadratic Equations

View Set

CCHS 9th Literature/Comp , CCHS GA-Foundations of Algebra , CCHS Health and Personal Fitness ( 1 full credit) , CCHS Introduction to Business and Technology, 6/21 (SECOND)

View Set

Labor Pain Mgt and Fetal Assessment_EAQ

View Set

MED SURG 3, study set 1- inflammation, wound healing, and altered immune response

View Set