Warning: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in ..../includes/class_bbcode.php on line 2958

Warning: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in ..../includes/class_bbcode.php on line 2958
Official Java Thread - Page 2
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 34

Thread: Official Java Thread

  1. #16
    Respected Member
    Join Date
    Jul 2006
    Location
    .
    Posts
    15,215
    Rep Power
    1037

    Default

    Any value greater than 255? Well, I tried 266 and the program gives me the value 100001010 when I run it (as expected)...?

    Hmm...I see. So that would probably used the String.charAt() method?

    Then I might need a loop...something like...

    i = 0;

    While(i<=args.length)

    i++;

    Thats to "walk along" the length of string I suppose...I'll see what I can do.
    Last edited by Zero; 13-11-2008 at 21:57.

  2. #17
    Forum Addict!
    Join Date
    May 2006
    Location
    in space
    Age
    38
    Posts
    1,699
    Rep Power
    287

    Default

    i need help with my program if any1s got a chance

    ima upload the java file and c if u can get it to work prop

    im doin a noughts and crosses game, and am tryin to play against the computer

    im having a problem in making the computer make its move after ive made mine

    [ATTACHMENT REMOVED UPON REQUEST]
    Last edited by DJ B4VVY; 29-07-2009 at 18:48.





  3. #18
    Loyal Member Evil_Genious's Avatar
    Join Date
    May 2007
    Location
    The Future
    Posts
    3,753
    Rep Power
    812

    Default

    I know this is very ugly dirty code... But please bear in mind, I'm new to Java myself and I've been up since 5am LOL.. Anyway... Here's what I came up with, it works... There's no error checking so if you don't send in valid binary and not letters, it doesn't check... Have a look at it, see what you think, maybe it'll jog your train of thought....

    Code:
    	public static int binToDec (String b)
    	{
    		// Declarations
    		int string_length = 0;
    		int loop_control = 0;
    		int inc_b = 1;
    		char toconvert = 'a';
    		int converted = 0;
    		int return_value = 0;
    		
    		// Initialise
    		string_length = b.length();
    		loop_control = string_length;
    		
    		// Process binary data		
    		while (loop_control > 0)
    		{
    			toconvert = b.charAt((loop_control - 1));
    			converted = Integer.parseInt(Character.toString(toconvert));
    			
    			return_value = return_value + (converted * inc_b);
    			
    			inc_b = inc_b * 2;
    			loop_control = loop_control - 1;
    									
    		}		
    		
    		// Return value
    		return return_value;
    		
    	}

    Call it with that main thing you had...

    "I'll let you break me off, but I won't let you break my heart"

  4. #19
    Respected Member
    Join Date
    Jul 2006
    Location
    .
    Posts
    15,215
    Rep Power
    1037

    Default

    Quote Originally Posted by vertigo View Post
    i need help with my program if any1s got a chance

    ima upload the java file and c if u can get it to work prop

    im doin a noughts and crosses game, and am tryin to play against the computer

    im having a problem in making the computer make its move after ive made mine
    Bloody hell, thats way to advanced for me...and probably EG too! lol unless he's overtaken me...!
    Last edited by Zero; 13-11-2008 at 23:22.

  5. #20
    Loyal Member Evil_Genious's Avatar
    Join Date
    May 2007
    Location
    The Future
    Posts
    3,753
    Rep Power
    812

    Default

    LOL I know better than open a .zip file with code in it.......

    "I'll let you break me off, but I won't let you break my heart"

  6. #21
    Loyal Member Evil_Genious's Avatar
    Join Date
    May 2007
    Location
    The Future
    Posts
    3,753
    Rep Power
    812

    Default

    I opened it anyway, I haven't done Swing. So can't tell you.... Soz.... And would need to run it to see what it does... LOL and I don't even know how to do that...

    "I'll let you break me off, but I won't let you break my heart"

  7. #22
    Forum Addict!
    Join Date
    May 2006
    Location
    in space
    Age
    38
    Posts
    1,699
    Rep Power
    287

    Default

    open it up with any editor program

    and run it off from dos

    using the javac - compile and java to run

    if u guys dnt no how to do it nvm then, i jus thought id give it a shot





  8. #23
    Respected Member
    Join Date
    Jul 2006
    Location
    .
    Posts
    15,215
    Rep Power
    1037

    Default

    Quote Originally Posted by Evil_Genious View Post
    I know this is very ugly dirty code... But please bear in mind, I'm new to Java myself and I've been up since 5am LOL.. Anyway... Here's what I came up with, it works... There's no error checking so if you don't send in valid binary and not letters, it doesn't check... Have a look at it, see what you think, maybe it'll jog your train of thought....

    Code:
     
        public static int binToDec (String b)
        {
            // Declarations
            int string_length = 0;
            int loop_control = 0;
            int inc_b = 1;
            char toconvert = 'a';
            int converted = 0;
            int return_value = 0;
     
            // Initialise
            string_length = b.length();
            loop_control = string_length;
     
            // Process binary data        
            while (loop_control > 0)
            {
                toconvert = b.charAt((loop_control - 1));
                converted = Integer.parseInt(Character.toString(toconvert));
     
                return_value = return_value + (converted * inc_b);
     
                inc_b = inc_b * 2;
                loop_control = loop_control - 1;
     
            }        
     
            // Return value
            return return_value;
     
        }

    Call it with that main thing you had...
    LOL...the joy's of working in CSci eh...5AM starts!

    I've desk-checked the loop and I understand it...its given me an idea...I think I'd try to implement it as a for loop and I've got a vague idea how to do that...

    I'm a bit confused why you assigned "a" to the variable toConvert of type char though...at the declarations section?
    Last edited by Zero; 14-11-2008 at 00:04.

  9. #24
    Loyal Member Evil_Genious's Avatar
    Join Date
    May 2007
    Location
    The Future
    Posts
    3,753
    Rep Power
    812

    Default

    Code:
    C:\>cd C:\oxo2
    
    C:\>javac oxo2.java
    Note: oxo2.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    
    C:\>javac -Xlint oxo2.java
    oxo2.java:112: warning: [unchecked] unchecked call to add(E) as a member of the
    raw type java.util.ArrayList
                        al.add(box);                                          // add
    s the box to the arraylist
                              ^
    1 warning
    Doesn't compile. I don't know enough about Java's libraries to see what the problem is... Maybe that was the problem you're lookin to solve.....

    "I'll let you break me off, but I won't let you break my heart"

  10. #25
    Loyal Member Evil_Genious's Avatar
    Join Date
    May 2007
    Location
    The Future
    Posts
    3,753
    Rep Power
    812

    Default

    Quote Originally Posted by Zero View Post
    I'm a bit confused why you assigned "a" to the variable toConvert of type char though...at the declarations section?

    No reason, just for the sake of initialising it to a known value. Until I set it to something I don't know whats in there, could be garbage... So set it to something when you declare it, just to ensure that something that was in memory at the time isn't in there. Which could be anything...

    "I'll let you break me off, but I won't let you break my heart"

  11. #26
    Respected Member
    Join Date
    Jul 2006
    Location
    .
    Posts
    15,215
    Rep Power
    1037

    Default

    Oh ok...Hmm...I was reading that when you initialise the variable...without the value...then java uses the default value?

    Thats only in Java I think...

    The default for boolean is False, default for int is 0, default for string is null and default for float is 0.0F etc...

    Well, my brains not functioning anymore now..so I think I'll give it another shot 2mo and then show what I've got in here..

  12. #27
    Forum Addict!
    Join Date
    May 2006
    Location
    in space
    Age
    38
    Posts
    1,699
    Rep Power
    287

    Default

    i fixed my game and it works perfectly





  13. #28
    Respected Member
    Join Date
    Jul 2006
    Location
    .
    Posts
    15,215
    Rep Power
    1037

    Default

    Thanks for the sticky mr/mrs mod!

    Right, take a look at this;

    Code:
    public static int binToDec (String b)
     
    {
      
    //this method uses a "for" loop
    
    int result = 0;
      
        for (int i = 0; i < b.length(); i++)
        
        {
    
        result = (result * 2) + (b.charAt(i) - '0');
    
        }
      
      return result;
     
    }
     
    //end of method
    I think that more or less wraps it up...

    I haven't really tested it fully and there isn't anything for error/exception handling, so its fairly basic. It still gets the job done though!
    Last edited by Zero; 14-11-2008 at 18:09.

  14. #29
    Respected Member
    Join Date
    Jul 2006
    Location
    .
    Posts
    15,215
    Rep Power
    1037

    Default

    Note: I didn't write that code.

    I can't seem to follow the logic however... the length of the string determines how many time the method loops, and the "b.charAt" extracts each character from the string... and then minuses zero from it? How does that work? And surely in binary each digit has a certain weight (1,2,4,8,16,32,64,128, etc.)...?
    Is that sorted out using the expression "result = result * 2" ?

  15. #30
    Loyal Member Evil_Genious's Avatar
    Join Date
    May 2007
    Location
    The Future
    Posts
    3,753
    Rep Power
    812

    Default

    Looks as if someone is offsetting the ASCII decimal of 0 from whatever number it is to calculate the number that is in the string.

    Ascii Table - ASCII character codes and html, octal, hex and decimal chart conversion

    So if you have 3 the ASCII decimal of 3 is -> 51.

    And 0 in ASCII decimal is -> 48

    so: the calculation: '3' - '0' is really doing:

    51 - 48 = 3



    Yeah it make sense LOLL.... Far simpler than the tripe I wrote....

    "I'll let you break me off, but I won't let you break my heart"

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. The Official GTA: IV Thread
    By DJ B4VVY in forum Technology, Hardware, Software and Games
    Replies: 94
    Last Post: 07-11-2008, 17:34
  2. Euro 08 - Official Thread
    By Cheeky_Princess in forum Local, National and International Sports
    Replies: 84
    Last Post: 28-06-2008, 11:07
  3. Official Music Thread
    By mindstate in forum Music and Radio
    Replies: 26
    Last Post: 16-05-2008, 09:17
  4. official joke on the member above u thread
    By mindstate in forum Arcade Chat + Fun & Games Talk
    Replies: 23
    Last Post: 10-11-2007, 22:45

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
The Asian Place is the best Desi social Asian Forum on the internet - who needs Facebook?

We have the greatest membership of adults on our boards doing what they do best, having fun, socialising and sharing cultures! We have some of the greatest moderators on our boards who ensure you receive the best and only the best experience from our forums.

The Asian Place was first established in August 08, 2004 where it began on a free forum provider, there were limitations in running a free forum so we had to migrate to our own servers leaving a years worth of data. Nevertheless we're here to take show you how to have fun the Desi way! We are dedicated in bringing you the best online experience like you have never experienced before! Join us today and find out for yourself! Our ideas are always unique if not different than any other place you will find on the internet.

Remember there's facebook and there's us the two are not the same.
Links
- Twitter
- Facebook
Follow us! #TheAsianPlace
Join Today
Join today for an epic time @ The Asian Place! Register Now