Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help asap!!! just a few questions I don't understand Multiple choice 4. Assume that these string variables have been declared: String str1 = new

Please help asap!!! just a few questions I don't understand

Multiple choice

4. Assume that these string variables have been declared:

String str1 = new String ("fred"); String str2 = new String ("Fred");

What is the value of the following expression? str1.equals(str2);

A.) true B.) false C.) fred D.) equal E.) fred.equals(Fred)

7. Given the following code:

if (n==2) { k-= 2; } else if (n==3) { k-=3; }

can be rewritten as if () { ; }

where and are chosen so that the rewritten code performs the same task as the original code. Assume that both n and k are integer variables.

Which of the following could be used as ? (1) (n==2) || (n==3) (2) (n==2) && (n==3) (3) (n>=2) && (n<=3)

A.) 1 only B.) 2 only C.) 3 only D.) 1 and 3 only E.) 2 and 3 only

8. What is stored in str after the following code executes?

String str = "Computer Science"; int i = 0; while (i <8) { if (str.indexOf("m")

9. What is the value of b after the following code executes?

int a = 2, b = 0; while (a <10) { b = 6; while (b>a) { b--; } a+=b; }

A.) 2 B.) 3 C.) 4 D.) 5 E.) 6

10. The following code is designed to set index to a location of the first occurrence of target in the array a, and to set index to -1 if target is not found in a.

index=0; while (a [index] !=target){ index++ } if (a [index] !=target){ index=-1 } Which of the following describes the condition under which this program segment will fail to perform the task described?

A.) Whenever target is the first element of the array. B.) Whenever target is the last element of the array. C.) Whenever target is not present in the array. D.) whenever Target is -1 E.) Whenever target = a [target]

11. Assume that a is an array of two or more integers, and that b and c are intergers.

What is the result of the following code? c=0; b=1; if (a.length>0) { c = a [0]; } while (b

A.) b contains the highest value in the array. B.) b contains the lowest value in the array. C.) c contains the highest value in the array D.) c contains the lowest value in the array. E.) An endless loop occurs.

12. Suppose the following array is declared:

int [ ] grades = {88, 92, 95, 83,};

What is the value of grades.length?

A.) 3 B.) 4 C.) 5 D.) 89.5 E.) -1

13. Suppose the following array is declared:

int [ ] grades = {88, 92, 95, 83,}; and the following interger is declared: int index = 10-2*4

What is the value of grades [index]?

A.) An ArrayIndexOutOfBoundsException occurs. B.) 88 C.) 92 D.) 95 E.) 83

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

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions