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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started