AP Computer Science A Unit 2 Exam With
Correct Solutions 2024
Consider .the .following .variable .declarations.
int .a .= .5;
int .b .= .4;
double .x .= .5;
double .y .= .4;
Which .of .the .following .expressions .would .evaluate .to .the .number, .1?
1. .(int) .x ./ .y
2. .a ./ .b
3. .a .% .b .- .correct .answer.All .of .them. .(1 ., .2, .and .3)
Consider .the .following .variable .declarations.
1. .double .x .= .(int) .3.4
2. .int .y .= .(int) .5 ./ .2 ., .5
3. .String .z .= .new .String(" .") .- .correct .answer.1 .and .3
Consider .String .a .below. .Which .of .the .following .would .create .a .new .String .with .the .value,
."ram"?
String .a .= .new .String .("Java .Program"); .- .correct .answer.String .b .= .a.substring(9);
Better .code .will .NOT .type .in .a .static .number .to .produce .words .near .the .end .of .the .String
.and .instead, .uses .length. .Which .of .the .following .will .result .in ."ram" .in .a .better .way .than
.#2 .did? .- .correct .answer.String .b .= .a.substring(a.length()-3);
What .special .type .of .data .is .identified .it .has .methods ., .unlike .primitive .data? .Another
.giveaway .that .this .is .not .primitive .data .is .that .variables .of .this .type .begin .with .a .capital
.letter. .- .correct .answer.Objects
Consider .the .code .segment .below. .What .is .the .result .that .is .printed .on .the .screen?
String .six .= .new .String .("Question .6");
int .find .= .six.indexOf("q");
Correct Solutions 2024
Consider .the .following .variable .declarations.
int .a .= .5;
int .b .= .4;
double .x .= .5;
double .y .= .4;
Which .of .the .following .expressions .would .evaluate .to .the .number, .1?
1. .(int) .x ./ .y
2. .a ./ .b
3. .a .% .b .- .correct .answer.All .of .them. .(1 ., .2, .and .3)
Consider .the .following .variable .declarations.
1. .double .x .= .(int) .3.4
2. .int .y .= .(int) .5 ./ .2 ., .5
3. .String .z .= .new .String(" .") .- .correct .answer.1 .and .3
Consider .String .a .below. .Which .of .the .following .would .create .a .new .String .with .the .value,
."ram"?
String .a .= .new .String .("Java .Program"); .- .correct .answer.String .b .= .a.substring(9);
Better .code .will .NOT .type .in .a .static .number .to .produce .words .near .the .end .of .the .String
.and .instead, .uses .length. .Which .of .the .following .will .result .in ."ram" .in .a .better .way .than
.#2 .did? .- .correct .answer.String .b .= .a.substring(a.length()-3);
What .special .type .of .data .is .identified .it .has .methods ., .unlike .primitive .data? .Another
.giveaway .that .this .is .not .primitive .data .is .that .variables .of .this .type .begin .with .a .capital
.letter. .- .correct .answer.Objects
Consider .the .code .segment .below. .What .is .the .result .that .is .printed .on .the .screen?
String .six .= .new .String .("Question .6");
int .find .= .six.indexOf("q");