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