Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-04-2008, 11:51 AM
Member
 
Join Date: Mar 2008
Posts: 8
googgoo is on a distinguished road
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.
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; }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-04-2008, 12:24 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
What is the len means, a filed in your class. Is that correctly initialized?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on September 4, 2008)

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-04-2008, 12:27 PM
Member
 
Join Date: Mar 2008
Posts: 8
googgoo is on a distinguished road
len is length of charArray
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-04-2008, 12:36 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
You return the index in wrong place.

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; }
There actually I return the 0 if there is no any character is found. Change it properly depend on your application.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on September 4, 2008)

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 04-04-2008, 12:46 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Rather than 0, you have to use a number which is not hold an index of your array.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on September 4, 2008)

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 04-04-2008, 01:16 PM
Member
 
Join Date: Mar 2008
Posts: 8
googgoo is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 04-04-2008, 11:33 PM
Member
 
Join Date: Feb 2008
Posts: 22
new_2_java is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 04-05-2008, 09:46 AM
Member
 
Join Date: Mar 2008
Posts: 8
googgoo is on a distinguished road
user enter a char
and I keep it in inputChar variable.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hi, need some urgent help! jdark New To Java 2 04-18-2008 07:50 AM
please help urgent ananas7777 AWT / Swing 2 12-25-2007 09:30 AM
NEED urgent help... bezdapez New To Java 7 11-27-2007 05:40 PM
need urgent help... SCS17 New To Java 1 11-13-2007 08:52 AM
Very Urgent Swamipsn New To Java 2 08-01-2007 02:56 PM


All times are GMT +3. The time now is 04:11 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org