The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Java Help
|
Homework - Any help is welcome..beginner java homework
Discuss Any help is welcome..beginner java homework in the Java Help forum on Dev Shed. Any help is welcome..beginner java homework Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 19th, 2012, 10:16 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 1
Time spent in forums: 15 m 26 sec
Reputation Power: 0
|
|
Homework - 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;
}
} 
|

November 19th, 2012, 11:05 PM
|
 |
Contributing User
|
|
|
|
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
|

November 20th, 2012, 07:26 AM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
Quote: | 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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|