Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Fill in the code for the following class methods. The following method return

ID: 3614685 • Letter: 1

Question

1. Fill in the code for the following class methods.
  1. The following method returns the position of the firstoccurrence of a given character in a given string. The positionstarts from 0 for the first character in the string. The methodshould return -1 if the character does not appear in the string.For example, the call indexOf('t',"iteration") would return 1, andthe call indexOf('s',"iteration") would return -1. (You are notallowed to use the String indexOf method.)
     public static int indexOf(char c, String str)
    {
    // fill this in
    }
  2. Given two String parameters, the following method returns trueif they are the same string of characters, and false otherwise.Note: You cannot use the equals String method; in otherwords, you actually have to write the code that compares the twostrings character by character.
     public static boolean stringsAreEqual(String s1, String s2)
    {
    // fill this in
    }
  1. The following method returns the position of the firstoccurrence of a given character in a given string. The positionstarts from 0 for the first character in the string. The methodshould return -1 if the character does not appear in the string.For example, the call indexOf('t',"iteration") would return 1, andthe call indexOf('s',"iteration") would return -1. (You are notallowed to use the String indexOf method.)
     public static int indexOf(char c, String str)
    {
    // fill this in
    }
  2. Given two String parameters, the following method returns trueif they are the same string of characters, and false otherwise.Note: You cannot use the equals String method; in otherwords, you actually have to write the code that compares the twostrings character by character.
     public static boolean stringsAreEqual(String s1, String s2)
    {
    // fill this in
    }

Explanation / Answer

Dear... Here is the code... 1)    public staticint indexOf(char c,String str)    {
          inti;          for(i=0;i<str.length();i++          {            if(str.charAt(i)==c)                return i;          }           return-1;     } 2)    public staticboolean stringsAreEqual(String s1, String s2)     {        if(s1.equals(s2))             return true;         else           return false;      } Hope thiswill help you... Hope thiswill help you...