Free Puzzle Questions with Answer using Java, C#, JavaScript and PHP

Java Quiz - Get Filtered Character

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package getfilteredcharacter;

/**
 *
 * @author Bereket
 */
public class GetFilteredCharacter {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        char[] sampleData = {'a', 'b', 'c'};
        
        char[] result = FilterCharacter(sampleData, 0,2);
        
        System.out.println(result);
    }
    
    static char[] FilterCharacter(char[] givenArray, int startIndex, int length){
        
        if(startIndex < 0 || startIndex > givenArray.length-1){
            return null;
        }
        else if((startIndex + length) > givenArray.length){
            return null;
        }
        else{
            char[] outputArray = new char[length];
            int x = 0;
            for(int i=startIndex; x< length; i++){
                outputArray[x] = givenArray[i];
                x++;
            }
            
            return outputArray;
        }
    }
}