Tau Empire Codex 2013 | Army Builder Program
Dark Angels Codex 2013
Chaos Daemons Codex 2013
Chaos Space Marines Codex 2012

Warhammer 40k Forum Tau Online

 

Warhammer 40K Forum

Anyone know Java well?
Reply
Old 18 Oct 2008, 13:37   #1 (permalink)
Shas'Ui
 
Join Date: Jan 2008
Location: Ireland
Posts: 698
Default Anyone know Java well?

I'm doing Java in college right, and I've got to do a program that checks if a sentence is a palindrome or not.

I need to know if a string can be treated like an array of characters like it can in C++? And how would I check if a string is empty(as this has to be checked too).
__________________
Click on these little dudes to get a slightly bigger little dude!




http://www.travian.co.uk/?uc=uk1
RonanB1011 is offline   Reply With Quote
Old 18 Oct 2008, 13:42   #2 (permalink)
Shas'O
 
Join Date: Apr 2004
Location: Retired back into the depths of the Internets.
Posts: 6,440
Send a message via MSN to mace
Default Re: Anyone know Java well?

I'm currently learning Java at Uni..

Firstly I'd take the string, and trim it, and convert to lower case.

i.e.
String s = "hello world!";
s = s.trim().toLowerCase();

As for treating it as an array, yes you can! use .charAt(int index) and .length() to help you out.
so s.length() would return 12, and you can view each character by using s.chartAt(n) for n from 0 to 11.

If it is empty, s.length() would return 0.
__________________
mace is offline   Reply With Quote
Old 18 Oct 2008, 13:46   #3 (permalink)
Shas'Ui
 
Join Date: Jan 2008
Location: Ireland
Posts: 698
Default Re: Anyone know Java well?

Thanks mate. ;D
__________________
Click on these little dudes to get a slightly bigger little dude!




http://www.travian.co.uk/?uc=uk1
RonanB1011 is offline   Reply With Quote
Old 31 Oct 2008, 20:28   #4 (permalink)
Shas'O
 
Join Date: Jun 2006
Posts: 6,130
Default Re: Anyone know Java well?

Random bit of advice, keep in mind that by default, strings can be null. So typically, you'll check to ensure your string isn't null before doing anything with it.

If you do a charAt() beyond the length, you'll get an exception thrown, so if it's something complex, you'll probably also want some exception handling(always a good idea regardless).
__________________
Latest Project: Game Design Forums. Register now to get a low user ID, or reserve a forum for your own project.

My various opinions and tacticas, in article form: Ad clicks always appreciated.

Latest article topic: Video game design

Best free webhost Ive found yet: http://www.ultrawebsitehosting.com/2353.html
Tyndmyr is offline   Reply With Quote
Old 09 Nov 2008, 19:38   #5 (permalink)
Shas'Ui
 
Join Date: Oct 2006
Location: Norway, oslo
Posts: 994
Default Re: Anyone know Java well?

String to char array.
String s = "wakka";
char[] c = s. toCharArray();

Get to know the java api, it's full of usefull nuggets.
__________________
Food and sleep is no substitute for coffee.
And I do need some coffee...

"One thing about programming, is to make everything boring... You don't want a 100 tonne turbine to get exiting"
GeorgeCrane is offline   Reply With Quote
Reply

Bookmarks


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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Program Debugging Genmotty Computers, Science and Technology 4 05 Nov 2009 10:46
Java hates me too... Tau-killer Computers, Science and Technology 3 23 Mar 2009 13:11
Java hates me... GeekyGator Computers, Science and Technology 25 05 Mar 2009 20:14
Stupid Java question. GeekyGator Computers, Science and Technology 3 15 Aug 2008 08:27
a java page demo azr9 Computers, Science and Technology 4 17 Aug 2007 19:13