Results 1 to 8 of 8
  1. #1
    googgoo is offline Member
    Join Date
    Mar 2008
    Posts
    8
    Rep Power
    0

    Default 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;
    	}

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  3. #3
    googgoo is offline Member
    Join Date
    Mar 2008
    Posts
    8
    Rep Power
    0

    Default

    len is length of charArray

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    You return the index in wrong place.

    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;
                    }
    There actually I return the 0 if there is no any character is found. Change it properly depend on your application.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  6. #6
    googgoo is offline Member
    Join Date
    Mar 2008
    Posts
    8
    Rep Power
    0

    Default

    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.

  7. #7
    new_2_java is offline Member
    Join Date
    Feb 2008
    Posts
    60
    Rep Power
    0

    Default

    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

  8. #8
    googgoo is offline Member
    Join Date
    Mar 2008
    Posts
    8
    Rep Power
    0

Similar Threads

  1. Hi, need some urgent help!
    By jdark in forum New To Java
    Replies: 2
    Last Post: 04-18-2008, 06:50 AM
  2. please help urgent
    By ananas7777 in forum AWT / Swing
    Replies: 2
    Last Post: 12-25-2007, 08:30 AM
  3. NEED urgent help...
    By bezdapez in forum New To Java
    Replies: 7
    Last Post: 11-27-2007, 04:40 PM
  4. need urgent help...
    By SCS17 in forum New To Java
    Replies: 1
    Last Post: 11-13-2007, 07:52 AM
  5. Very Urgent
    By Swamipsn in forum New To Java
    Replies: 2
    Last Post: 08-01-2007, 01:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •