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 3 of 3

Thread: Help me with my code

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help me with my code

    The code in bold is not making sense to me...the string array holds 8 different elements containing 4 characters each. Ex. string[0] = "0010"
    string[1] = "0100"

    When if(string[0] == "0010")...gets executed...the line below....s.append(2);.....is not executed...it is skipped...any ideas?

     char[] divide = binaryNumber.toCharArray();
            char[] copy = new char[32];
            String[] string = new String[8];
            int v;
     
            for(int j = 0; j < 32; ++j)
                copy[j] = '0';
     
            for(int c = 0; c < divide.length; ++c)
                copy[c] = divide[c];
     
            StringBuffer a = new StringBuffer();
            StringBuffer b = new StringBuffer();
            StringBuffer c = new StringBuffer();
            StringBuffer d = new StringBuffer();
            StringBuffer e = new StringBuffer();
            StringBuffer f = new StringBuffer();
            StringBuffer g = new StringBuffer();
            StringBuffer h = new StringBuffer();
     
            for(int i = 0; i < 4; ++i)
                a.append(copy[i]); 
            string[0] = a.toString();
     
            for(int j = 4; j < 8; ++j)
                b.append(copy[j]);
            string[1] = b.toString();
     
            for(int k = 8; k < 12; ++k)
                c.append(copy[k]); 
            string[2] = c.toString();
     
            for(int l = 12; l < 16; ++l)
                d.append(copy[l]);
            string[3] = d.toString();
     
            for(int m = 16; m < 20; ++m)
                e.append(copy[m]); 
            string[4] = e.toString();
     
            for(int n = 20; n < 24; ++n)
                f.append(copy[n]);
            string[5] = f.toString();
     
            for(int o = 24; o < 28; ++o)
                g.append(copy[o]); 
            string[6] = g.toString();
     
            for(int p = 28; p < 32; ++p)
                h.append(copy[p]);
            string[7] = h.toString();
     
     
            StringBuffer s = new StringBuffer();
     
            [B]for(int y = 0; y < 8; ++y){
                if(string[y]=="0000")
                    ;
                if(string[y]=="0001")
                    s.append(1);
                if(string[y]=="0010")
                    s.append(2);
                if(string[y]=="0011")
                    s.append(3);
                if(string[y]=="0100")
                    s.append(4);
                if(string[y]=="0101")
                    s.append(5);
                if(string[y]=="0110")
                    s.append(6);
                if(string[y]=="0111")
                    s.append(7);
                if(string[y]=="1000")
                    s.append(8);
                if(string[y]=="1001")
                    s.append(9);
                if(string[y]=="1010")
                    s.append('A');
                if(string[y]=="1011")
                    s.append('B');
                if(string[y]=="1100")
                    s.append('C');
                if(string[y]=="1101")
                    s.append('D');
                if(string[y]=="1110")
                    s.append('E');
                if(string[y]=="1111")
                    s.append('F');[/B]        }


  2. #2
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts
    Thanks and Regards
    Dan Brown

    Common Java Mistakes

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Help me with my code

    As Dan has just pointed out.. You have made a common Java mistake.

    if(string[y]=="0000")

    should be

    if(string[y].equals("0000"))

    It's worth reading the link he posted.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  4. The Following User Says Thank You to JavaPF For This Useful Post:

    javapenguin (February 4th, 2011)