Test: AP Computer Science A

Consider the following code:

 

public static void main(String[] args) {

     System.out.println(foo("This is my favorite: Yay for programming!!!"));

}

 

public static String foo(String s) {

     if(!s.equals("")) {

          char c = s.charAt(0);

          if(c >= 'A' && c <= 'Z') {

               return Character.toLowerCase(c) + foo(s.substring(1));

          } else if (c >= 'a' && c <= 'z'){

               return Character.toUpperCase(c) + foo(s.substring(1));

          }

          return foo(s.substring(1));

     }

     return "";

}

1.

What is the output for the main function above?

ThIs iS mY fAvOriTe

tHIS IS MY FAVORITE: yAY FOR PROGRAMMING!!!

tHIS IS MYFAVORITE

ThIs iS mY fAvOriTe: YaY fOr PrOgRaMmIng!!!

tHISISMYFAVORITEyAYFORPROGRAMMING

1/12 questions

0%

Access results and powerful study features!

Take 15 seconds to create an account.
Start now! Create your free account and get access to features like:
  • Full length diagnostic tests
  • Invite your friends
  • Access hundreds of practice tests
  • Monitor your progress over time
  • Manage your tests and results
  • Monitor the progress of your class & students
By clicking Create Account you agree that you are at least 13 years old and you agree to the Varsity Tutors LLC Terms of Use and Privacy Policy.
Learning Tools by Varsity Tutors