I am writing a program, and the solution I have involves deleting certain elements from an array until there are none. My code is below, but the error it shows is no return statement. This is because I don't have an else statement for some ifs, does anyone know how to get through this? Maybe there is a simpler way to simply delete elements from an array. Thanks

import java.util.*;
import java.lang.*;
class week12_15 {

    public static void main(String[] args) 
    {
        if(canSpell("quijibo", "jib")) System.out.print("True");
    }

    public static boolean canSpell(String tiles, String word)
    {

        char[] charTiles = tiles.toCharArray();
        char[] charWord = word.toCharArray();
        int x = 0;
        System.out.println(Arrays.toString(charTiles));
        System.out.println(Arrays.toString(charWord));
        for(int i = 0; i<charTiles.length -1; i++)
        {
            char a = charTiles[i];
            for(int y = 0; i<charWord.length -1; i++)
            {
                char b = charWord[y];
                if(b == a)
                {
                    for(int w = 0; i<charTiles.length-1; w++)
                    {
                        if(charTiles[w] != b)
                        {
                            charTiles[w] = charTiles[w];
                        }
                    }
                    for(int z = 0; i<charWord.length-1; z++)
                    {
                        if(charWord[z] != b)
                        {
                            charWord[z] = charWord[z];
                        }
                    }   
                }
                else
                {
                    return false;
                }
            }
            if(charWord.length == 0)
            {
                return true;
            }
            return false;
        }

    }

}
This article has been dead for over six months. Start a new discussion instead.