96.3k views
3 votes
Java 1

Question 20
What will be printed by the following code?

String str = "Have a nice day!";
System.out.println(str.length());

a. Have a nice day
b. 16
c. 13
d. Have
e. 4

Question 21
Examine this code:

String str = "Hello World!" ;

What is the index of the character 'W'?

a. 6
b. 7
c. 5
d. 8
e. 2

User Xeno Lupus
by
6.7k points

1 Answer

6 votes

Answer:

Q20 b.16

Q21 a.6

Explanation:

count charcters Have a nice day! ==16

Q21 why 6

because index start with 0 and not 1

just count

H ==> 0

e==> 1

l==> 2

.

.

W=>6

User Brittny
by
6.5k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.