Results 1 to 13 of 13
Like Tree1Likes
  • 1 Post By Fubarable

Thread: Need help with index of coincedence

  1. #1
    tripline is offline Member
    Join Date
    Oct 2011
    Posts
    19
    Rep Power
    0

    Default Need help with index of coincedence

    Write a program that accepts two strings of the same length and determines their index of coincidence. For normal written English, the index of coincidence averages about 6.6%, while for random strings it is 1/ 26, or around 3.8%.

    Is there a website I can view to learn to do this? I tried searching but counldn't find anything.
    Last edited by tripline; 10-30-2011 at 04:43 PM.

  2. #2
    jMaster's Avatar
    jMaster is offline Member
    Join Date
    Oct 2011
    Posts
    16
    Rep Power
    0

    Default Re: Need help with index of coincedence

    I don't understand the problem here... Do you want to output 2 randomly generated strings of the same length?

  3. #3
    tripline is offline Member
    Join Date
    Oct 2011
    Posts
    19
    Rep Power
    0

    Default Re: Need help with index of coincedence

    Question edited

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Need help with index of coincedence

    I'm confused: Why not simply try to write something like this yourself?

  5. #5
    tripline is offline Member
    Join Date
    Oct 2011
    Posts
    19
    Rep Power
    0

    Default Re: Need help with index of coincedence

    Because the book did not have any instructions on how to do this. I just need to know how to check for matching letters.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Need help with index of coincedence

    Quote Originally Posted by tripline View Post
    Because the book did not have any instructions on how to do this. I just need to know how to check for matching letters.
    You can check if one char is the same as another with ==, and likely do this inside of nested for loops. The book isn't going to tell you exactly what to do in every programming situation. Instead it will give you general direction, and you're supposed to use your clever intellect to apply this information to help you solve this problem. In other words, please don't look to find a solution online, but instead put in some thought and figure it out on your own. You'll be glad you did.

  7. #7
    jMaster's Avatar
    jMaster is offline Member
    Join Date
    Oct 2011
    Posts
    16
    Rep Power
    0

    Default Re: Need help with index of coincedence

    Oh. I'm sorry it was my fault I don't know about that.

    What you are looking to learn is called String Handling.

    try something like this:

    private void findIndexOfCoincidence(String word1, String word2) {
    int count = 0;
    if(word1.length() == word2.length()) {
    for(int i = 0; i < word1.length(); i++){
    if(word1.charAt(i) == word2.charAt(i)){
    count++;
    }
    }
    int index = (count/word1.length()) * 100;
    }
    }

    I hope this is right theres a whole load of easels out now hungry for my laptop light and i wrote that in this post. Hope its what you're looking for..

  8. #8
    jMaster's Avatar
    jMaster is offline Member
    Join Date
    Oct 2011
    Posts
    16
    Rep Power
    0

    Default Re: Need help with index of coincedence

    Sorry that the indenting all got cut off i didn't do that

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Need help with index of coincedence

    jMaster: better to answer specific questions than to spoon-feed ready-made solutions. My experience here has taught me that doing this only teaches the student to beg and not to learn (though he will protest to the contrary, just wait). Also, a cursory glance at your solution suggests it may run into int division issues.
    doWhile likes this.

  10. #10
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Need help with index of coincedence


  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Need help with index of coincedence

    Quote Originally Posted by doWhile View Post
    Thanks for the heads up. Original poster, please read copeg's links as they apply to this and all other programming fora that I know of.

  12. #12
    jMaster's Avatar
    jMaster is offline Member
    Join Date
    Oct 2011
    Posts
    16
    Rep Power
    0

    Default Re: Need help with index of coincedence

    Yes ofcourse index should be a double and either word1.length or count.

    Okay i'm new to this forum things because my teacher said i'm already so good I need forums to make me know everything. I guess spoon-feeding is a bit of a waste of time also huh, ok i'll listen and not spoon-feed solutions.

  13. #13
    tripline is offline Member
    Join Date
    Oct 2011
    Posts
    19
    Rep Power
    0

    Default Re: Need help with index of coincedence

    I am completely new at this. I have only been using public (...) so I don't know much about private. But thanks, ill try to figure your method out.

    well, Im not completely blank. I meant it when I said i only needed help with matching letters.
    I think either check each char one at a time (don't know how to write that)
    or change string to array then check index one at a time.

    import java.util.*;
    public class indexofcoincedence
    {public static void main (String[] args)
    {
    int len1=0; int len2=0;
    char[] string1; char[] string2;
    Scanner input = new Scanner(System.in);
    System.out.println( "Enter a word");
    String word1 = input.nextLine();
    System.out.println( "Enter a word");
    String word2 = input.nextLine();
    len1=word1.length();
    len2=word2.length();
    string1=word1.toCharArray();
    string2=word2.toCharArray();
    }
    }

    This is as far as i got.

Similar Threads

  1. Redirecting port 80 index to port 8080 index
    By chyrl in forum Advanced Java
    Replies: 0
    Last Post: 11-30-2010, 03:15 PM
  2. Replies: 0
    Last Post: 10-29-2010, 08:15 PM
  3. Index tables
    By andy16 in forum JDBC
    Replies: 1
    Last Post: 05-27-2010, 09:48 AM
  4. Index of an int
    By wake in forum New To Java
    Replies: 4
    Last Post: 02-24-2010, 01:54 PM
  5. I can't run my index.jsp
    By gissah in forum New To Java
    Replies: 0
    Last Post: 03-23-2009, 01:42 AM

Posting Permissions

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