Click here to download the IntelliJ project for this exercise. Alternatively, you can find all the exercices on this git repository
This exercise is already available in your IntelliJ as a project.
What you need to do is described in the comments at the top of the file in src/main/java/
.
package basics; public class PatternMatching { /** * Look for one sequence of characters (the pattern) in an input * string, and return the position of the pattern in the string * (if present). If the pattern is present multiple times in the * string, the function must return the leftmost occurrence of the * pattern (i.e. the occurrence whose index is the lowest). The * function must be case-sensitive (i.e. <code>Hello</code> is not * the same as <code>hello</code>). * @param pattern The pattern to look for. * @param value The string to look in. * @result The index of the leftmost occurrence of the pattern in * the string. Must be <code>-1</code> if the pattern is absent * from the string. **/ public static int find(String pattern, String value) { return -1; } }
- Instruction provided at the top of the source file on IntelliJ.
- Debug using small and easy unit tests provided in junit tests, it can also help to clarify the instructions.