Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Need help on decoding what this part of the code does

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help on decoding what this part of the code does

    I have been trying to decode a program that was made but i'm having a hard time understanding what this part of the code does can anyone tell me what each variable does?
    i think its for the checking part of the game but i'm unsure what chin and chin2 does as well as int t,x,a specifically
    i'm sorry that the part i don't understand is quite long and thank you for your help in advance

    int chin[] = new int[6];
    int chin2[] = new int[6];
    char bin[] = new char[6];
    bin[0] = 'Q'; bin[1] = 'W'; bin[2] = 'E'; bin[3] = 'R'; bin[4] = 'T'; bin[5] = 'Y';
    char a[] = new char[4];
    int t[] = new int[4];
    for (int x = 0;x<4;x++){
    a[x] = (f.charAt(x));
    }
    for (int i = 0; i< 4;i++){
    for (int tim = 0; tim<6;tim++){
    if (a[i] == bin[tim]){
    t[i] = tim +1;
    }}
    }for (int x = 0;x<4;x++){
    if (t[x] == 1){
    chin[0] = chin[0]+1;
    } else if (t[x] == 2){
    chin[1] = chin[1]+1;
    } else if (t[x] == 3){
    chin[2] = chin[2]+1;
    } else if (t[x] == 4){
    chin[3] = chin[3]+1;
    } else if (t[x] == 5){
    chin[4] = chin[4]+1;
    } else if (t[x] == 6){
    chin[5] = chin[5]+1;
    }
    if (d[x] == 1){
    chin2[0] = chin2[0]+1;
    } else if (d[x] == 2){
    chin2[1] = chin2[1]+1;
    } else if (d[x] == 3){
    chin2[2] = chin2[2]+1;
    } else if (d[x] == 4){
    chin2[3] = chin2[3]+1;
    } else if (d[x] == 5){
    chin2[4] = chin2[4]+1;
    } else if (d[x] == 6){
    chin2[5] = chin2[5]+1;
    }
    }

    for (int x = 0; x <= 3; x++) {
    if (d[x] == t[x]) {
    v++;
    }
    }

    for (int x = 0;x<6;x++){
    if (chin[x] <= chin2[x]){
    count2 = count2 + chin[x];
    } else {
    count2 = count2 + chin2[x]; }
    } count2 = count2 - v;
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Need help on decoding what this part of the code does

    Welcome to the Forum! Please read this topic to learn how to post your code correctly along with other useful info for newcomers.

    Don't expect an answer until you've posted correctly, and then ask a question that shows you've made some effort. For example, show what you think the code does and ask us if we agree. You might also try running it. We won't help you if it appears you've just copied code from the Internet and want to understand it so that you can comment it before you turn it in as your own.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need help on decoding what this part of the code does

    A useful technique for finding out what some code does is to add lots of println statements to print out the values of the variables that are used so you can see what the computer is doing as it executes the code.
    For arrays:
    System.out.println("an ID "+ java.util.Arrays.toString(theArrayName));
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Dec 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help on decoding what this part of the code does

    Thanks for that technique it helped me figure out what it does ill be sure to remember it next time. sorry for posting it wrong and still helping me though ill be sure to try to post a question correctly next time

Similar Threads

  1. What is wrong in My code. Going to Else part..Can you please suggest me.
    By Umasri in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 4th, 2013, 09:53 AM
  2. Replies: 9
    Last Post: October 4th, 2013, 09:53 AM
  3. What does this part of the code mean?
    By jean28 in forum Java Theory & Questions
    Replies: 5
    Last Post: September 23rd, 2012, 11:47 PM
  4. JSON Decoding help
    By brucegregory in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 3rd, 2012, 12:40 PM
  5. What does this short part of a code do?
    By Kranti1992 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 28th, 2012, 11:31 AM