Test: Computer Science

1.

Which of the following is a method that takes a string and an integer as parameters, using the integer to increase each character value in the string before returning the new value?  (For instance, a 2 applied to abc should become cde.)

public void myMethod(String s,int i) {

            String r = "";

            for(int j = 0; j < s.length(); j++) {

                        r += (char)(s.charAt(j) + i);

            }

}

public String myMethod(String s,int i) {

            String r = "";

            for(int j = 0; j < s.length(); j++) {

                        r += (s.charAt(j) + i);

            }

            return r;

}

public int myMethod(String s,int i) {

            String r = "";

            for(int j = 0; j < s.length(); j++) {

                        r += (char)(s.charAt(j) + i);

            }

            return r.length();

}

public String myMethod(String s,int i) {

            String r = "";

            for(int j = 0; j < s.length(); j++) {

                        r += (char)(s.charAt(j) + i);

            }

            return r;

}

None of the others

1/3 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