| |
| |
| |
|
Page: 1 2 3 4 5 6 7
Comments:
<0> and read back into thearray[i] <0> or can u directly manipulate thearray[i]? <1> p*** the array of strings, for each string in the array call the format method and ***ign the result back into the array... <0> well.. i tried following.. <2> okay, that one works <0> temp[t] = temp[t].toLowercase() <0> but it didnt compile.. <1> "it didn[']t compile" really isn't a good description of the problem, heh. <1> it gave an error message? <1> Oh... well for a start, it's toLowerCase <0> oh :) <0> bummer ;) <0> oops.. compiled X) <2> I suspect that people will object if I just give him a working method though <1> smsie yeah
<1> his teacher especially <1> ;) <2> dave-e: I'm not his teacher :) <1> um... <1> his teacher will object <1> because you solved his homework... <2> I'll never meet his teacher <1> See the topic. <2> I know <2> that's why I haven't given him a working method <1> Feel free to try to teach... pseudo code, advice, whatever... but full answers to simple stuff like this just causes more questions down the line. <2> raki: roughsketch of what you need: a method which accepts an array of strings as a parameter. It loops over the strings in the array setting each one to the format you want (inside the array pased). <0> ya.. thats what ive got.. <2> does it work? <0> ill tell u in time ;P <0> dave-e my teacher wouldnt mind as its not an ***ignment.. <0> as i said we have no ***ignments.. just an exam in a week.. <0> just trying to learn as much as possible <0> smsie <0> http://rafb.net/p/iaUWx054.html <0> thats what it looks like <1> If the strings are never used in their original form, then formatting them straight after they are retreived means the code is less complex. <2> hmm, interesting. foreach doesn't work for this...have to do it the old fashioned way :) <0> line 7 and8 doesnt work though.. <2> raki: that's an awkward way to do it <0> X) <0> not surprised <1> If the trings are never used in their original form... why mess around with the array like this? <1> It's not a learning experience to do something the long way around, heh... <0> no idea really tbh.. <0> as u said.. <0> since i read line by line.. <1> You should learn to write the most concise program. <0> i might aswell just insert that on the line instead.. <1> Surely you get the most marks for the simplest answer to the problem? <0> indeed.. <0> "elegance" as stolterman wouldve put it X( <2> raki: what's "slask"? It's not used at all <0> oh.. i used that b4 smsie.. <0> just forgot to remove it.. <0> i read temp[i] into slask <0> and then formated slask <0> and read back into temp[] <2> awkward all the way <0> =) <0> i agree on the array matter.. <0> it seems dumb to overdo it <0> when i can just send a string instead.. <0> which aswell woulld render more useful overall.. <1> 1) Get your string 2) Make the string lower case 3) Make a string buffer out of the string so it's mutable 4) Get the first char 5) Make the char upper case 6) Set the char in the string buffer to the uppercase version 7) Make the string buffer back into a String <1> That'd be my version. <2> dave-e: still feels awkward <1> Java is awkward. <1> Have a better method (other than using a sensible language with mutable strings)? <3> seems to me that it simply is an issue of design. And once your design has quirks things become awkward. <2> String format(String s){ return s.substring(0,1).toUpperCase() + s.substring(1).toLowerCase(); } <2> it's a one-liner <2> why would I want to go messing about with string buffers and all that? <1> I suspect you already are. <0> well <0> part of the format, which i havent told u X)
<0> is removing "-" <0> if found in string :o <0> hmm or no <0> nvm.. ill sort that differently.. <0> http://rafb.net/p/codbRI81.html <0> thats what i made from what u said earlier dave-e.. <1> smsie what do you think + does? <0> before the talk of stringbuffer.. <1> Or uses I should say <1> raki yeah, at a glance that seems like a similar thing <2> dave-e: I don't care what it does behind the scenes. It can do what it likes. I don't have to write the code for what it's doing <0> i havent gotten to stringbuffers yet im afraid.. and since u prolly arent interested in holding my hand through it i gotta keep it on a level where i actually get somwhere =) <2> dealing with stringbuffers by hand isn't needed for this problem. As dave-e right says, they're probably used behind the scenes, but you shouldn't have to care about that <1> Well, they are used behind the scenes. Whether you need to care about it probably depends on how many strings this thing is processing. <2> admittedly, my solution is very lisplike rather than javalike. But it works,and is simple. <0> oh crap.. <1> Although, as it's a homework ***ignment with 20 Strings to deal with, I'd go with smsie's version. <1> :) <0> hahah its no homework.. =) <1> Yeah yeah <0> we dont have homework at my uni cl*** :) <2> dave-e: I've usually found that less lines of code is *generally* better :) There are times when it isn't, but by and large, it leads to less errors IMO <0> smsie less lines of code is a good quality <0> but, when learning how to do things <0> id like to overcomplicate matters <0> to learn new ways of going around problems <0> anyway, i ran into a slight problem.. <0> i read directly in to temp[].. temp[i] = JOption.. <0> is there anyway of going around it or should i just do <0> tmp = format(JOption..); temp[i] = tmp; <0> hmm and i need to check JOption.. for null aswell <4> hi and congrats guys <0> but that can be done within format() by if(tmp ==) return null; else theformatbusiness.. <0> which makes the method more independent aswell i reckon.. <1> Congrats? One of us had a baby?? :D <1> raki should format ever be p***ed null? <0> yes.. <1> Why? <0> it might aswell.. <0> well tmp = format(JOption..); <0> would return null if pressed cancel.. <0> err p*** null.. <1> um, so handle that there <1> you shouldn't be p***ing nulls around for no reason <0> why not inside format? <1> because format(null) makes no sense <0> indeed.. but then if someone is stupid enough to send null into the format it doesnt give exception.. <1> value = ...; if(value == null) { do something because the user cancelled } else { format(value) } <0> ay.. <1> Then throw an exception from format if you care about it <1> if(s == null) throw new SomeException( "s can not be null" ); or whatever <1> you shouldn't just take the null in and p*** it back out unless that's the desired effect <1> otherwise you're making the error go further into the program and making it harder to find where it originated from <0> true dave-e.. <0> thanks for ur comments.. <0> c[0] = Character.toUpperCase(c); <0> fs = Character.toString(c); <0> can u see whats wrong with those 2 lines? <1> An unchecked exception of course... maybe IllegalArgument or something <0> oh.. <0> c[0] on the first one atleast.. <0> and then toString(c[]) perhaps? :e <0> first one was correct.. <0> just the toString that doesnt work.. <0> fs = Character.toString(c); that line is wrong because its not a Character its a CharArray i guess.. <2> raki: use the appropriate String constructor <2> fs=new String(c); <0> ah thanks <0> just read that in forum <0> ok just one final problem.. <0> when u dont enter any text into the dialog i get exception <0> since i cant create chararray of a blank string :P <0> i tried .isEmpty() with little luck.. <1> Check if it's empty straight away
Return to
#java or Go to some related
logs:
#AllNiteCafe #linux #linux 041106 jack #skype carbidej #AllNiteCafe Warning hedear #javascript #mirc
|
|