#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Unhappy Any help is welcome..beginner java homework


    So this is part of the program I'm creating.
    I have alphabets assigned to each number
    2=A or B or C
    (and so on.. in the code as matrix)

    I have a sample word (in this code (XAZ)
    and sample number "929"

    my method is supposed to return "true"
    as
    9==X
    2==A
    9==Z

    however somehow it doesn't work..
    can anybody give me feed back, I'm in a rush and my code might be a little hard to read

    import java.util.*;
    import java.lang.Character;

    public class test
    { static char[][] numAlphabet={{},{},
    {'A','B','C'},
    {'D','E','F'},
    {'G','H','I'},
    {'J','K','L'},
    {'M','N','O'},
    {'P','Q','R','S'},
    {'T','U','V'},
    {'W','X','Y','Z'}};
    public static void main(String[]args)
    {
    String num="929";
    String word="XAZ";
    wordMatch(num,word);
    }


    public static boolean wordMatch(String num, String word)
    {

    int integerValue;
    boolean flag=false;
    int j=0;
    int k=0;

    integerValue=(int)num.charAt(0)-(int)'0';

    for(j=0;j<numAlphabet[integerValue].length&&flag==false;j++){

    if(numAlphabet[integerValue[j]==word.charAt(0)&&num.length()>1)
    {
    wordMatch(num.substring(0+1,num.length()),word.substring(0+1,word.length()));
    }
    else if(numAlphabet[integerValue][j]==word.charAt(0)&&num.length()==1)
    {flag=true;}
    }
    System.out.println(flag);

    return flag;
    }

    }
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    73
    Rep Power
    15
    When you say it doesn't work, do you mean it does not compile or does not do what you want? Please include the error?

    There is a typo in this line:

    Code:
    if(numAlphabet[integerValue[j]==word.charAt(0)&&num.length()>1)
    sould be

    Code:
    if(numAlphabet[integerValue][j]==word.charAt(0)&&num.length()>1)
    Hope this helps,
    slink
  4. #3
  5. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    my code might be a little hard to read
    Please edit your post and wrap the code in code tags to make it easier to read and understand.

IMN logo majestic logo threadwatch logo seochat tools logo