AP Computer Science A Exam With
Complete Questions And Answers 2024
Consider .the .following .code .segment.
System.out.println("W");
System.out.println("X");
System.out.print("Y");
System.out.print("Z");
What .is .printed .as .a .result .of .executing .the .code .segment? .- .correct .answer.D. .
W
X
YZ
Consider .the .following .code .segment.
System.out.print("cat .");
System.out.println("dog .");
System.out.println("horse .");
System.out.print("cow .");
What .is .printed .as .a .result .of .executing .the .code .segment? .- .correct .answer.B. .cat .dog
horse
cow
Consider .the .following .code .segment.
System.out.print("Hello!");
System.out.println("How .");
System.out.print("are .");
System.out.print("you?");
What .is .printed .as .a .result .of .executing .the .code .segment? .- .correct .answer.D. .Hello!How
are .you?
Consider .the .following .code .segment.
System.out.println(hello); .// .Line .1
System.out.print(world); .// .Line .2
The .code .segment .is .intended .to .produce .the .following .output .but .does .not .work .as
.intended.
hello
,world
Which .of .the .following .changes .can .be .made .so .that .the .code .segment .produces .the
.intended .output? .- .correct .answer.D. .Changing .print .in .line .2 .to .println
Consider .the .following .code .segment.
System.out.print("Ready"); .// .Line .1
System.out.print("Set"); .// .Line .2
System.out.print("Go!"); .// .Line .3
The .code .segment .is .intended .to .produce .the .following .output .but .may .not .work .as
.intended.
Ready
Set
Go!
Which .change, .if .any, .can .be .made .so .that .the .code .segment .produces .the .intended
.output? .- .correct .answer.A. .Changing .print .to .println .in .lines .1 .and .2
Each .of .the .following .code .segments .is .intended .to .print .the .word .Hello. .Which .of .the
.following .code .segments .works .as .intended?
I. .System.out.print("Hello");
II. .System.out.print(Hello);
III. .System.out.print(He);
.System.out.print(llo); .- .correct .answer.A. .I .only
Which .statement .correctly .declares .a .variable .that .can .store .a .temperature .rounded .to
.the .nearest .tenth .of .a .degree? .- .correct .answer.B. .double .patientTemp;
A .teacher .determines .student .percentages .in .a .course .as .the .points .a .student .earns
.divided .by .the .total .points .available .in .the .grading .period. .Points .are .awarded .only .in
.whole .number .increments, .but .student .percentages .are .to .be .stored .as .decimals.
The .following .code .segment .appears .in .a .program .used .to .compute .student .percentages.
.Points .that .a .student .earns .are .stored .in .pointsEarned, .the .total .points .available .in .the
.grading .period .are .stored .in .totalPoints, .and .the .student .percentage .is .stored .in
.percentage.
int .pointsEarned;
/* .missing .code .*/
Which .of .the .following .is .most .appropriate .to .replace ./* .missing .code .*/ .in .the .program? .-
.correct .answer.C. .int .totalPoints;
double .percentage;
Consider .the .following .code .segment:
/* .data .type .1 .*/ .x .= .0.5;
/* .data .type .2 .*/ .y .= .true;
Which .of .the .following .best .describes .the .data .types .that .should .be .used .to .replace/* .data
.type .1 .*/ .and ./* .data .type .2 .*/ .so .that .the .code .segment .compiles .without .error? .- .correct
.answer.D. .The .variable .x .should .be .declared .as .a .double .and .the .variable .y .should .be
.declared .as .a .boolean.
,Consider .the .following .code .segment.
int .x;
int .y;
x .= .3;
y .= ./* .missing .expression .*/;
x .= .1 .+ .2 .* .y;
System.out.print(x);
System.out.println(y);
Which .of .the .following .can .be .used .as .a .replacement .for ./* .missing .expression .*/ .so .that
.the .code .segment .prints .94 .? .- .correct .answer.D. .x .+ .1
The .volume .of .a .cylinder .is .equal .to .the .height .times .the .area .of .the .circular .base. .The
.area .of .the .circular .base .is .equal .to .π .(pi) .times .the .square .of .the .radius.
The .code .segment .below .is .intended .to .compute .and .print .the .volume .of .a .cylinder .with
.radius .r .and .height .h. .Assume .that .the .double .variables .r, .h, .and .pi .have .been .properly
.declared .and .initialized.
/* .missing .code .*/
System.out.print(volume);
Which .of .the .following .can .be .used .to .replace ./* .missing .code .*/ .so .that .the .code .segment
.works .as .intended?
I. .double .baseArea .= .pi .* .r .* .r;double .volume .= .baseArea .* .h;
II. .double .volume .= .pi .* .r .* .r;volume .= .volume .* .h;
III. .double .volume .= .pi .* .r .* .r .* .h; .- .correct .answer.E. .I, .II, .and .III
Consider .the .following .code .segment.
int .x .= .10;
int .y .= .20;
/* .missing .code .*/
System.out.print(top ./ .bottom);
Which .of .the .following .replacements .for ./* .missing .code .*/ .will .cause .an
.ArithmeticException .to .occur?
I. .int .top .= .x .- .y;int .bottom .= .y .- .x;
II. .int .top .= .2 .* .x;int .bottom .= .y .- .top;
III. .int .top .= .x .+ .y;int .bottom .= .2 .* .top; .- .correct .answer.B. .II .only
Consider .the .following .code .segment.
int .a .= .1;
int .b .= .2;
int .c .= .3;
int .d .= .4;
double .x .= .a .+ .b .* .c .% .d;
What .is .the .value .of .x .when .the .code .segment .has .been .executed? .- .correct .answer.C.
.3.0
Which .of .the .following .arithmetic .expressions .evaluates .to .1 .?
, I. .2 ./ .5 .% .3
II. .2 ./ .(5 .% .3)
III. .2 ./ .5 .+ .1 .- .correct .answer.D. .II .and .III .only
Consider .the .code .segment .below.
int .x .= .10;
int .y .= .20;
System.out.print(y .+ .x ./ .y);
What .is .printed .as .a .result .of .executing .the .code .segment? .- .correct .answer.D. .20
Consider .the .following .code .segment.
int .j .= .10;
int .k .= .8;
j .+= .2;
k .+= .j;
System.out.print(j);
System.out.print(" .");
System.out.println(k);
What .is .printed .when .the .code .segment .is .executed? .- .correct .answer.E. .12 .20
Consider .the .following .code .segment.
int .x .= .0;
x++;
x .+= .1;
x .= .x .+ .1;
x .-= .-1;
System.out.println(x);
What .is .printed .when .the .code .segment .has .been .executed? .- .correct .answer.E. .4
Consider .the .following .code .segment.
int .num .= .5;
num .*= .2;
num .%= .6;
What .is .the .value .of .num .after .the .code .segment .is .executed? .- .correct .answer.C. .4
Consider .the .following .code .segment.
int .x .= ./* .initial .value .not .shown .*/;
int .y .= ./* .initial .value .not .shown .*/;
int .z .= .x;
z ./= .y;
z .+= .2;
Which .of .the .following .best .describes .the .behavior .of .the .code .segment? .- .correct
.answer.D. .It .sets .z .to .(x ./ .y) .+ .2.
Consider .the .following .code .segment, .which .is .intended .to .calculate .the .average .of .two
.quiz .scores.
Complete Questions And Answers 2024
Consider .the .following .code .segment.
System.out.println("W");
System.out.println("X");
System.out.print("Y");
System.out.print("Z");
What .is .printed .as .a .result .of .executing .the .code .segment? .- .correct .answer.D. .
W
X
YZ
Consider .the .following .code .segment.
System.out.print("cat .");
System.out.println("dog .");
System.out.println("horse .");
System.out.print("cow .");
What .is .printed .as .a .result .of .executing .the .code .segment? .- .correct .answer.B. .cat .dog
horse
cow
Consider .the .following .code .segment.
System.out.print("Hello!");
System.out.println("How .");
System.out.print("are .");
System.out.print("you?");
What .is .printed .as .a .result .of .executing .the .code .segment? .- .correct .answer.D. .Hello!How
are .you?
Consider .the .following .code .segment.
System.out.println(hello); .// .Line .1
System.out.print(world); .// .Line .2
The .code .segment .is .intended .to .produce .the .following .output .but .does .not .work .as
.intended.
hello
,world
Which .of .the .following .changes .can .be .made .so .that .the .code .segment .produces .the
.intended .output? .- .correct .answer.D. .Changing .print .in .line .2 .to .println
Consider .the .following .code .segment.
System.out.print("Ready"); .// .Line .1
System.out.print("Set"); .// .Line .2
System.out.print("Go!"); .// .Line .3
The .code .segment .is .intended .to .produce .the .following .output .but .may .not .work .as
.intended.
Ready
Set
Go!
Which .change, .if .any, .can .be .made .so .that .the .code .segment .produces .the .intended
.output? .- .correct .answer.A. .Changing .print .to .println .in .lines .1 .and .2
Each .of .the .following .code .segments .is .intended .to .print .the .word .Hello. .Which .of .the
.following .code .segments .works .as .intended?
I. .System.out.print("Hello");
II. .System.out.print(Hello);
III. .System.out.print(He);
.System.out.print(llo); .- .correct .answer.A. .I .only
Which .statement .correctly .declares .a .variable .that .can .store .a .temperature .rounded .to
.the .nearest .tenth .of .a .degree? .- .correct .answer.B. .double .patientTemp;
A .teacher .determines .student .percentages .in .a .course .as .the .points .a .student .earns
.divided .by .the .total .points .available .in .the .grading .period. .Points .are .awarded .only .in
.whole .number .increments, .but .student .percentages .are .to .be .stored .as .decimals.
The .following .code .segment .appears .in .a .program .used .to .compute .student .percentages.
.Points .that .a .student .earns .are .stored .in .pointsEarned, .the .total .points .available .in .the
.grading .period .are .stored .in .totalPoints, .and .the .student .percentage .is .stored .in
.percentage.
int .pointsEarned;
/* .missing .code .*/
Which .of .the .following .is .most .appropriate .to .replace ./* .missing .code .*/ .in .the .program? .-
.correct .answer.C. .int .totalPoints;
double .percentage;
Consider .the .following .code .segment:
/* .data .type .1 .*/ .x .= .0.5;
/* .data .type .2 .*/ .y .= .true;
Which .of .the .following .best .describes .the .data .types .that .should .be .used .to .replace/* .data
.type .1 .*/ .and ./* .data .type .2 .*/ .so .that .the .code .segment .compiles .without .error? .- .correct
.answer.D. .The .variable .x .should .be .declared .as .a .double .and .the .variable .y .should .be
.declared .as .a .boolean.
,Consider .the .following .code .segment.
int .x;
int .y;
x .= .3;
y .= ./* .missing .expression .*/;
x .= .1 .+ .2 .* .y;
System.out.print(x);
System.out.println(y);
Which .of .the .following .can .be .used .as .a .replacement .for ./* .missing .expression .*/ .so .that
.the .code .segment .prints .94 .? .- .correct .answer.D. .x .+ .1
The .volume .of .a .cylinder .is .equal .to .the .height .times .the .area .of .the .circular .base. .The
.area .of .the .circular .base .is .equal .to .π .(pi) .times .the .square .of .the .radius.
The .code .segment .below .is .intended .to .compute .and .print .the .volume .of .a .cylinder .with
.radius .r .and .height .h. .Assume .that .the .double .variables .r, .h, .and .pi .have .been .properly
.declared .and .initialized.
/* .missing .code .*/
System.out.print(volume);
Which .of .the .following .can .be .used .to .replace ./* .missing .code .*/ .so .that .the .code .segment
.works .as .intended?
I. .double .baseArea .= .pi .* .r .* .r;double .volume .= .baseArea .* .h;
II. .double .volume .= .pi .* .r .* .r;volume .= .volume .* .h;
III. .double .volume .= .pi .* .r .* .r .* .h; .- .correct .answer.E. .I, .II, .and .III
Consider .the .following .code .segment.
int .x .= .10;
int .y .= .20;
/* .missing .code .*/
System.out.print(top ./ .bottom);
Which .of .the .following .replacements .for ./* .missing .code .*/ .will .cause .an
.ArithmeticException .to .occur?
I. .int .top .= .x .- .y;int .bottom .= .y .- .x;
II. .int .top .= .2 .* .x;int .bottom .= .y .- .top;
III. .int .top .= .x .+ .y;int .bottom .= .2 .* .top; .- .correct .answer.B. .II .only
Consider .the .following .code .segment.
int .a .= .1;
int .b .= .2;
int .c .= .3;
int .d .= .4;
double .x .= .a .+ .b .* .c .% .d;
What .is .the .value .of .x .when .the .code .segment .has .been .executed? .- .correct .answer.C.
.3.0
Which .of .the .following .arithmetic .expressions .evaluates .to .1 .?
, I. .2 ./ .5 .% .3
II. .2 ./ .(5 .% .3)
III. .2 ./ .5 .+ .1 .- .correct .answer.D. .II .and .III .only
Consider .the .code .segment .below.
int .x .= .10;
int .y .= .20;
System.out.print(y .+ .x ./ .y);
What .is .printed .as .a .result .of .executing .the .code .segment? .- .correct .answer.D. .20
Consider .the .following .code .segment.
int .j .= .10;
int .k .= .8;
j .+= .2;
k .+= .j;
System.out.print(j);
System.out.print(" .");
System.out.println(k);
What .is .printed .when .the .code .segment .is .executed? .- .correct .answer.E. .12 .20
Consider .the .following .code .segment.
int .x .= .0;
x++;
x .+= .1;
x .= .x .+ .1;
x .-= .-1;
System.out.println(x);
What .is .printed .when .the .code .segment .has .been .executed? .- .correct .answer.E. .4
Consider .the .following .code .segment.
int .num .= .5;
num .*= .2;
num .%= .6;
What .is .the .value .of .num .after .the .code .segment .is .executed? .- .correct .answer.C. .4
Consider .the .following .code .segment.
int .x .= ./* .initial .value .not .shown .*/;
int .y .= ./* .initial .value .not .shown .*/;
int .z .= .x;
z ./= .y;
z .+= .2;
Which .of .the .following .best .describes .the .behavior .of .the .code .segment? .- .correct
.answer.D. .It .sets .z .to .(x ./ .y) .+ .2.
Consider .the .following .code .segment, .which .is .intended .to .calculate .the .average .of .two
.quiz .scores.