Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Chapter 4 82) Suppose s is a string with the value \"java\". What will be assign

ID: 3821331 • Letter: C

Question

Chapter 4

82)

Suppose s is a string with the value "java". What will be assigned to x if you execute the following code?

char x = s.charAt(4);

(2pts)

'a'

the empty string

Nothing will be assigned to x, because the execution causes the runtime error StringIndexOutofBoundsException.

a space

83)

Analyze the following code:

int i = 3434; double d = 3434.0;
System.out.printf("%5.1f %5.1f", i, d);

(2pts)

The code compiles and runs fine to displays 3434.0 3434.0.

The code compiles and runs fine to display 3434 3434.0.

i is an integer, but the format specifier %5.1f specifies a format for double value, so the code will not compile.

i is an integer, but the format specifier %5.1f specifies a format for double value, so, the code will still compile, but when it gets to this line, there will be a run-time error.

84)

Assume that the ASCII code for character c is 99. What is the printout of the following code?

System.out.println("a" + 'c');

(2pts)

a99

ac

9799

196

85)

Assume that the ASCII code for character c is 99 and for a is 97. What is the printout of the following code?

System.out.println('a' + 'c');

(2pts)

a99

ac

9799

196

Explanation / Answer

Question 82:

Answer:

Nothing will be assigned to x, because the execution causes the runtime error StringIndexOutofBoundsException.

as because "java" is stored in s and index starts from 0 and ends at 3

when you are accessing 4 index it gives out error java.lang.StringIndexOutOfBoundsException

Question 83:

Answer:

i is an integer, but the format specifier %5.1f specifies a format for double value, so, the code will still compile, but when it gets to this line, there will be a run-time error.

Question 84:

Answer:

ac

it just concate the string a with character c

Question 85:

Answer:

196

it adds both ASCII code 99 + 97 = 196

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote