Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 19th, 2012, 10:16 PM
ccck ccck is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 1 ccck User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 26 sec
Reputation Power: 0
Unhappy 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;
}

}

Reply With Quote
  #2  
Old November 19th, 2012, 11:05 PM
slink's Avatar
slink slink is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 73 slink User rank is Sergeant (500 - 2000 Reputation Level)slink User rank is Sergeant (500 - 2000 Reputation Level)slink User rank is Sergeant (500 - 2000 Reputation Level)slink User rank is Sergeant (500 - 2000 Reputation Level)slink User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 17 h 10 m 20 sec
Reputation Power: 14
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

Reply With Quote
  #3  
Old November 20th, 2012, 07:26 AM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,959 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 3 h 17 m 24 sec
Reputation Power: 345
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Homework - Any help is welcome..beginner java homework

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap