Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the method header public static String foo(int i). Which of the following could be a correct method call? (Note: in all of the examples

Consider the method header public static String foo(int i). Which of the

following could be a correct method call? (Note: in all of the examples below i is of type int,

and s is of type String).

a. String foo(int i)

b. String foo(i)

c. s = foo(i)

d. foo(String s)

2. For the loop given below, what is the final value of i when the loop is finished?

int i = 1;

int arr = {2, 3, 5};

while (i < arr.length) {

i = i + 1;

}

a. 1

b. 2

c. 3

d. 4

e. You cannot tell just from the code segment provided

f. The loop will never exit it is an infinite loop

3. Suppose you have a problem where you are trying to find the larger of two numbers. Which

ONE of the following Java programming concepts would be the best fit to use to solve this

problem?

a. while loop

b. if-else

c. String length

d. None of the above in the space below explain how you can choose the larger of two

values without using any of the above concepts

4. A Java program that is supposed to compute the average of an array of numbers tries to access a

number at an index larger than the length of the array. This is an example of what kind of error:

a. Runtime error

b. Syntax error

c. Array Too Small error

d. None of the above

5. What value does the variable msg have at the end of this segment of code?

int value = 31;

String msg = ;

if (value < 50) {

msg = Under 50!;

}

else if (value > 30) {

msg = Over 30!;

}

if (value < 25) {

msg = Under 25!;

}

a.

b. Under 25!

c. Over 30!

d. Under 50!

e. You cannot tell from the code provided

6. For the loop given below, how many times will the boolean expression (i < 2) be evaluated?

int i = 0;

while (i < 2) {

i = i + 1;

}

a. 0

b. 1

c. 2

d. 3

e. 4

f. The loop will never exit it is an infinite loop

7. If you declare an array as char[] cs = {4,3,2,1}, then the array element

cs[3] contains what value?

a. 1

b. 2

c. 3

d. 4

e. It is impossible to tell

8. What will be printed by the println statement at the end of this code segment?

int i = 2;

while ( i < 3 ) {

String msg = "Value: "+i;

i = i + 1;

}

System.out.println(msg);

a. Value: 0

b. Value: 1

c. Value: 2

d. Value: 3

e. None of the above the above segment has an error in it. In the space below give a brief

explanation of what the error is

9. The method declared with the header public static double oneThirdOf(int i)

returns:

a. An integer value

b. A double value

c. The value of the parameter i divided by 3

d. No value

e. You cannot tell from the information provided

10.If x, y and z are boolean variables, for what values of x, y and z does the expression

((!x && y) || z) evaluate to true? (Mark ALL that apply):

a. x=false, y=true, z=false

b. x=true, y=false, z=false

c. x=false, y=false, z=true

d. x=true, y=true, z=true

e. The expression can be true, but not for any of the assigned values listed above

f. The expression cannot be true, no matter how you assign values to x, y and z

11.If i, j and k are int variables, for what values of i,j and k does the expression

((( i < j) || (i < k)) && (j * k > 10)) evaluate to true? (Mark ALL that

apply):

a. i=8, j=9, k=1

b. i=4, j=3, k=5

c. i=8, j=10, k=1

d. i=11, j=11, k=9

e. None of the above assignments of i, j and k make the expression true

12.The following segment of code provides examples of which of the following (mark ALL that

apply):

i = 1024;

if (i % 2 == 0) {

i = i / 4;

}

a. boolean expression

b. integer expression

c. looping

d. branching

e. None of the above

13.Which of the following method headers are examples of procedures? (Mark ALL that apply)

a. private static void barfoo(int x, String s)

b. private static String foobar()

c. private static void foo(double x, char c)

d. private static int bar(String x)

e. None of the above are examples of functions

14.Which of the following facts about arrays and ArrayLists are false? (Mark ALL that apply)

a. Items in an array must all have the same type

b. The size of an array does not need to be known when it is created

c. The size of an ArrayList must be known when it is created

d. ArrayLists can never be empty

e. None of the above are false

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

Describe the three types of start-up firms.

Answered: 1 week ago