CSC 110 ASSIGNMENT 3 (2.9-2.15 AND 3.1-
3.2) EXAM 2025/2026 QUESTIONS AND
ANSWERS 100% PASS
Declare a String variable named mailingAddress. - ANS String mailingAddress;
Write the declaration of three String variables named win, place, and show. - ANS String win,
place,
show;
Write the declaration of a String variable named foreground and initialize it to "black". -
ANS String foreground = "black";
Declare a String variable named oneSpace, and initialize it to a String consisting of a single
space. - ANS String oneSpace = " ";
Declare a String variable named empty, and initialize it to the empty String. - ANS String
empty = "";
Assume that the String variable named foreground has already been declared. Assign it the
value "red". - ANS foreground = "red";
Assume that the String variable named text has already been declared. Assign to it the empty
string. - ANS text = "";
1 @COPYRIGHT 2025/2026 ALLRIGHTS RESERVED.
, There are two String variables, s1 and s2, that have already been declared and initialized. Write
some code that exchanges their values.
Declare any other variables as necessary. - ANS String temp = s1;
s1=s2;
s2=temp;
Write an expression that concatenates the String variable suffix onto the end of the String
variable prefix . - ANS prefix + suffix
Given a String variable word, write a String expression that parenthesizes the value of word. So,
if word contains "sadly", the value of the expression would be the String "(sadly)" - ANS "(" +
word + ")"
Given three String variables that have been declared and given values, gold, silver, and bronze,
write an expression whose value is the values of each these variables joined by a newline
character. So if gold, silver, and bronze, had the values "Arakawa", "Cohen", and "Slutskaya", the
expression, if it were printed would have the names "Arakawa", "Cohen", and "Slutskaya" each
appearing on a separate line. (Do NOT print anything in this exercise: just write the expression.)
- ANS gold + "\n" + silver + "\n" + bronze
Given three String variables that have been declared and given values, firstName, middleName,
and lastName, write an expression whose value is the values of each these variables joined by a
single space. So if firstName, middleName, and lastName, had the values "Big", "Bill", and
"Broonzy", the expression's value would be "Big Bill Broonzy". Alternatively, if firstName,
middleName, and lastName, had the values "Jerry", "Lee", and "Lewis", the expression's value
would be "Jerry Lee Lewis". - ANS firstName + " " + middleName + " " + lastName
Given a String variable named sentence that has been initialized, write an expression whose
value is the number of characters in the String referred to by sentence. -
ANS sentence.length()
2 @COPYRIGHT 2025/2026 ALLRIGHTS RESERVED.
3.2) EXAM 2025/2026 QUESTIONS AND
ANSWERS 100% PASS
Declare a String variable named mailingAddress. - ANS String mailingAddress;
Write the declaration of three String variables named win, place, and show. - ANS String win,
place,
show;
Write the declaration of a String variable named foreground and initialize it to "black". -
ANS String foreground = "black";
Declare a String variable named oneSpace, and initialize it to a String consisting of a single
space. - ANS String oneSpace = " ";
Declare a String variable named empty, and initialize it to the empty String. - ANS String
empty = "";
Assume that the String variable named foreground has already been declared. Assign it the
value "red". - ANS foreground = "red";
Assume that the String variable named text has already been declared. Assign to it the empty
string. - ANS text = "";
1 @COPYRIGHT 2025/2026 ALLRIGHTS RESERVED.
, There are two String variables, s1 and s2, that have already been declared and initialized. Write
some code that exchanges their values.
Declare any other variables as necessary. - ANS String temp = s1;
s1=s2;
s2=temp;
Write an expression that concatenates the String variable suffix onto the end of the String
variable prefix . - ANS prefix + suffix
Given a String variable word, write a String expression that parenthesizes the value of word. So,
if word contains "sadly", the value of the expression would be the String "(sadly)" - ANS "(" +
word + ")"
Given three String variables that have been declared and given values, gold, silver, and bronze,
write an expression whose value is the values of each these variables joined by a newline
character. So if gold, silver, and bronze, had the values "Arakawa", "Cohen", and "Slutskaya", the
expression, if it were printed would have the names "Arakawa", "Cohen", and "Slutskaya" each
appearing on a separate line. (Do NOT print anything in this exercise: just write the expression.)
- ANS gold + "\n" + silver + "\n" + bronze
Given three String variables that have been declared and given values, firstName, middleName,
and lastName, write an expression whose value is the values of each these variables joined by a
single space. So if firstName, middleName, and lastName, had the values "Big", "Bill", and
"Broonzy", the expression's value would be "Big Bill Broonzy". Alternatively, if firstName,
middleName, and lastName, had the values "Jerry", "Lee", and "Lewis", the expression's value
would be "Jerry Lee Lewis". - ANS firstName + " " + middleName + " " + lastName
Given a String variable named sentence that has been initialized, write an expression whose
value is the number of characters in the String referred to by sentence. -
ANS sentence.length()
2 @COPYRIGHT 2025/2026 ALLRIGHTS RESERVED.