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

tHISISMYFAVORITEyAYFORPROGRAMMING

tHIS IS MY FAVORITE: yAY FOR PROGRAMMING!!!

ThIs iS mY fAvOriTe: YaY fOr PrOgRaMmIng!!!

tHIS IS MYFAVORITE

1/12 questions

0%
Learning Tools by Varsity Tutors