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

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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!