Results 1 to 8 of 8
Thread: Help me ...urgent!
- 04-04-2008, 10:51 AM #1
Member
- Join Date
- Mar 2008
- Posts
- 8
- Rep Power
- 0
Help me ...urgent!
Hi !
I crate method Check() for comparing charArray and inputChar
In my code, I declared variable charArray such as char[] charArray={'A','N','T'}
and get input from keyboard each character and keep in variable inputChar
When get input 'A' I want compare charArray in index[0]
if equal ...to compare next index ...until last index equal then print "equal"
but my method not so,my method check char by char and no run on index.
How I solve this problem.
Java Code:public static int Check(char[] charArray , char inputChar){ for(index = 0;index<len;index++){ if(charArray[index] == inputChar){ index++; if(index == len){ System.out.println("equals"); } } } return index; }
- 04-04-2008, 11:24 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
What is the len means, a filed in your class. Is that correctly initialized?
- 04-04-2008, 11:27 AM #3
Member
- Join Date
- Mar 2008
- Posts
- 8
- Rep Power
- 0
len is length of charArray
- 04-04-2008, 11:36 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You return the index in wrong place.
There actually I return the 0 if there is no any character is found. Change it properly depend on your application.Java Code:public static int Check(char[] charArray , char inputChar){ for(int index = 0;index<charArray.length;index++){ if(charArray[index] == inputChar){ System.out.println("equals"); return index; } } return 0; }
- 04-04-2008, 11:46 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Rather than 0, you have to use a number which is not hold an index of your array.
- 04-04-2008, 12:16 PM #6
Member
- Join Date
- Mar 2008
- Posts
- 8
- Rep Power
- 0
if I want to specify first index for check is
index[0] and then if index[0] are equal let
check next index (index [1],... until last index)
How to solve?
Thanks.
- 04-04-2008, 10:33 PM #7
Member
- Join Date
- Feb 2008
- Posts
- 60
- Rep Power
- 0
What is the input? is it going to be something like "ABC"?
Or it's going to be like
'A'
'B'
'C'
?
what I mean, is that the user enters a string or chars
- 04-05-2008, 08:46 AM #8
Member
- Join Date
- Mar 2008
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
Hi, need some urgent help!
By jdark in forum New To JavaReplies: 2Last Post: 04-18-2008, 06:50 AM -
please help urgent
By ananas7777 in forum AWT / SwingReplies: 2Last Post: 12-25-2007, 08:30 AM -
NEED urgent help...
By bezdapez in forum New To JavaReplies: 7Last Post: 11-27-2007, 04:40 PM -
need urgent help...
By SCS17 in forum New To JavaReplies: 1Last Post: 11-13-2007, 07:52 AM -
Very Urgent
By Swamipsn in forum New To JavaReplies: 2Last Post: 08-01-2007, 01:56 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks