Professional Documents
Culture Documents
2. At a certain high school students receive letter grades based on the following scale.
Integer Score Letter Grade
93 or above A
From 84 to 92 inclusive B
From 75 to 83 inclusive C
Below 75 F
Which of the following code segments will assign the correct string grade for a given integer score?
grade = "C";
if (score < 75)
grade = "F";
III. if (score >= 93)
grade = "A";
else if (score >= 84)
grade = "B";
else if (score >= 75)
grade = "C";
else
grade = "F";
3. Consider the following code segment
int x = //some number greater than 0
int n = 100;
if(x < 1000)
{
if (x > 1000)
{ n = 200; }
else
{ n = 300; }
}
else
{
if ( x < 1000)
{ n = 400; }
else
{ n = 300; }
}
System.out.println(n);
(A) true
(B) false
(C) a == b
(D) a != b
(E) !(a < b) && (a > b)
6. Consider the following code segment which uses properly defined and initialized int variables x and y.
What is the value of result after the code segment is executed if x has the value 15 and y has the value 5 ?
(A) Ad
(B) Adf
(C) d
(D) def
(E) ef
return r;
}
Which of the following combinations of x and y will cause this code segment to produce an error message?
I. x = 0, y = 0
II. x = 1, y = 2
III. x = 10, y = 2
(A) I only
(B) II only
(C) III only
(D) I and II only
(E) I, II, and III
if(num = 13
8. Write the method fixTeen which takes 1 integer parameter and returns its fixTeen value. For a fixTeen value,
all “teens” (13 – 19) count as 0 excepts for 15 or 16 which count double their original value (30 and 32 respectively.
-19)
All non-teen numbers count as their original value.
For example:
if(num =
fixTeen(10) returns 10
fixTeen(35) returns 35
15||16)
fixTeen(13) returns 0
fixTeen(15) returns 30
{
public static
{
Return
int fixTeen(int num)
num*2
}
else
{
return
0
9. Write the method noTeenSum which takes 3 int values and returns their fixTeen sum.
For Example
} 2, 3) returns 6
noTeenSum(1, 2, 3) returns 6
noTeenSum(1,
else1, 16) returns 35
noTeenSum(2, 13, 1) returns 3
noTeenSum(2,
10. Write the method blackjack, given 2 int values greater than 0, return whichever value is nearest to 21
without going over. Return 0 if they both go over.
For Example
blackjack(19, 21) returns 21
blackjack(21, 19) returns 21
blackjack(19, 22) returns 19
blackjack(23, 22) returns 0