The Asian Place - Desi Forum - Asian Forum  

Go Back   The Asian Place - Desi Forum - Asian Forum > Education - University - College - School > University
JOIN NOW! Mark Forums Read

Today we are discussing Official Java Thread in the University Forum.
Join in the discussion and express your views on Official Java Thread

"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 ..."
Reply
 
LinkBack Thread Tools
Old 13-11-2008, 21:56   #16 (permalink)
Zero
Respected Member
 
Zero's Avatar
Gentleman's Club
 
1 Highscore
Location: .
Gender: Male Male
Posts: 14,536
Rep Power: 703
Rep Level: Zero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond repute
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.

Signature


Last edited by Zero; 13-11-2008 at 21:57.
Zero is offline
 
Reply With Quote
Old 13-11-2008, 22:10   #17 (permalink)
vertigo
Forum Addict!
 
Location: in space
Age: 24
Gender: Male Male
Country:
Posts: 1,681
Rep Power: 115
Rep Level: vertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant future
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]

Signature





Last edited by DJ B4VVY; 29-07-2009 at 18:48.
vertigo is offline
 
Reply With Quote
Old 13-11-2008, 22:57   #18 (permalink)
Evil_Genious
Loyal Member
 
Evil_Genious's Avatar
 
Location: The Future
Gender: Male Male
Country:
Posts: 3,305
My Mood:
Rep Power: 504
Rep Level: Evil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond repute
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...

Signature

"You ain't have to do much to tempt me
titts and over what the age of consent be
that said you don't have to be that far over
sometimes jailbait is worth goin jail over"
Evil_Genious is offline
 
Reply With Quote
Sponsored Links
Old 13-11-2008, 23:22   #19 (permalink)
Zero
Respected Member
 
Zero's Avatar
Gentleman's Club
 
1 Highscore
Location: .
Gender: Male Male
Posts: 14,536
Rep Power: 703
Rep Level: Zero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond repute
Default

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...!

Signature


Last edited by Zero; 13-11-2008 at 23:22.
Zero is offline
 
Reply With Quote
Old 13-11-2008, 23:23   #20 (permalink)
Evil_Genious
Loyal Member
 
Evil_Genious's Avatar
 
Location: The Future
Gender: Male Male
Country:
Posts: 3,305
My Mood:
Rep Power: 504
Rep Level: Evil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond repute
Default

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

Signature

"You ain't have to do much to tempt me
titts and over what the age of consent be
that said you don't have to be that far over
sometimes jailbait is worth goin jail over"
Evil_Genious is offline
 
Reply With Quote
Old 13-11-2008, 23:30   #21 (permalink)
Evil_Genious
Loyal Member
 
Evil_Genious's Avatar
 
Location: The Future
Gender: Male Male
Country:
Posts: 3,305
My Mood:
Rep Power: 504
Rep Level: Evil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond repute
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...

Signature

"You ain't have to do much to tempt me
titts and over what the age of consent be
that said you don't have to be that far over
sometimes jailbait is worth goin jail over"
Evil_Genious is offline
 
Reply With Quote
Sponsored Links
Old 13-11-2008, 23:41   #22 (permalink)
vertigo
Forum Addict!
 
Location: in space
Age: 24
Gender: Male Male
Country:
Posts: 1,681
Rep Power: 115
Rep Level: vertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant future
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

Signature




vertigo is offline
 
Reply With Quote
Old 14-11-2008, 00:01   #23 (permalink)
Zero
Respected Member
 
Zero's Avatar
Gentleman's Club
 
1 Highscore
Location: .
Gender: Male Male
Posts: 14,536
Rep Power: 703
Rep Level: Zero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond repute
Default

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?

Signature


Last edited by Zero; 14-11-2008 at 00:04.
Zero is offline
 
Reply With Quote
Old 14-11-2008, 00:11   #24 (permalink)
Evil_Genious
Loyal Member
 
Evil_Genious's Avatar
 
Location: The Future
Gender: Male Male
Country:
Posts: 3,305
My Mood:
Rep Power: 504
Rep Level: Evil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond repute
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.....

Signature

"You ain't have to do much to tempt me
titts and over what the age of consent be
that said you don't have to be that far over
sometimes jailbait is worth goin jail over"
Evil_Genious is offline
 
Reply With Quote
Sponsored Links
Old 14-11-2008, 00:13   #25 (permalink)
Evil_Genious
Loyal Member
 
Evil_Genious's Avatar
 
Location: The Future
Gender: Male Male
Country:
Posts: 3,305
My Mood:
Rep Power: 504
Rep Level: Evil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond repute
Default

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...

Signature

"You ain't have to do much to tempt me
titts and over what the age of consent be
that said you don't have to be that far over
sometimes jailbait is worth goin jail over"
Evil_Genious is offline
 
Reply With Quote
Old 14-11-2008, 00:33   #26 (permalink)
Zero
Respected Member
 
Zero's Avatar
Gentleman's Club
 
1 Highscore
Location: .
Gender: Male Male
Posts: 14,536
Rep Power: 703
Rep Level: Zero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond repute
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..

Signature

Zero is offline
 
Reply With Quote
Old 14-11-2008, 00:47   #27 (permalink)
vertigo
Forum Addict!
 
Location: in space
Age: 24
Gender: Male Male
Country:
Posts: 1,681
Rep Power: 115
Rep Level: vertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant futurevertigo has a brilliant future
Default

i fixed my game and it works perfectly

Signature




vertigo is offline
 
Reply With Quote
Sponsored Links
Old 14-11-2008, 18:07   #28 (permalink)
Zero
Respected Member
 
Zero's Avatar
Gentleman's Club
 
1 Highscore
Location: .
Gender: Male Male
Posts: 14,536
Rep Power: 703
Rep Level: Zero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond repute
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!

Signature


Last edited by Zero; 14-11-2008 at 18:09.
Zero is offline
 
Reply With Quote
Old 14-11-2008, 18:15   #29 (permalink)
Zero
Respected Member
 
Zero's Avatar
Gentleman's Club
 
1 Highscore
Location: .
Gender: Male Male
Posts: 14,536
Rep Power: 703
Rep Level: Zero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond reputeZero has a reputation beyond repute
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" ?

Signature

Zero is offline
 
Reply With Quote
Old 14-11-2008, 20:49   #30 (permalink)
Evil_Genious
Loyal Member
 
Evil_Genious's Avatar
 
Location: The Future
Gender: Male Male
Country:
Posts: 3,305
My Mood:
Rep Power: 504
Rep Level: Evil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond reputeEvil_Genious has a reputation beyond repute
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....

Signature

"You ain't have to do much to tempt me
titts and over what the age of consent be
that said you don't have to be that far over
sometimes jailbait is worth goin jail over"
Evil_Genious is offline
 
Reply With Quote
Sponsored Links
Reply

Bookmarks

Tags
java, programming


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

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


All times are GMT +1. The time now is 12:59.

Contact Us - The Asian Place - Sitemap - Privacy Statement - Top

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc.
© The Asian Place 2004-2008 All Rights Reserved