Dsy Network www | forum | my | didattica | howto | wiki | el goog | stats | blog | dona | rappresentanti
Homepage
 Register   Calendar   Members  Faq   Search  Logout 
.dsy:it. : Powered by vBulletin version 2.3.1 .dsy:it. > Didattica > Corsi A - F > Fondamenti di architettura e programmazione > [JAVA][HELP] Stringbuffer
Pages (5): « 1 [2] 3 4 5 »   Last Thread   Next Thread
Author
Thread    Expand all | Contract all    Post New Thread    Post A Reply
Collapse
zeus
- mr. groove -

User info:
Registered: Sep 2004
Posts: 480 (0.06 al dì)
Location: Milano
Corso: Com Dig
Anno: Doctor
Time Online: 4 Days, 20:34:17 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

ehm.... sorry.....

a parte discorsi OT, ho provato il programma in una versione analoga alle vostre.

Non funziona.... mi dà errore "String Index out of range", qualsiasi valore dia all'indice del ciclo.
Ho provato a dare 0 e 1 con il ciclo in avanti, la lunghezza della stringa con il ciclo all'indietro... ho provato alcune modifiche, ma mi restituisce sempre lo stesso errore....

help? :uhmehehe:

thx

__________________
-- spammopoco --

08-12-2004 17:16
Click Here to See the Profile for zeus Click here to Send zeus a Private Message Find more posts by zeus Add zeus to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
0m4r
.grande:maestro.

User info:
Registered: Mar 2002
Posts: 7287 (0.84 al dì)
Location: Düsseldorf (DE)
Corso:
Anno: ESAMI FINITI
Time Online: 49 Days, 0:57:33 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

forse sarebbe piu utile vedere il codice, almeno una porzione di codice...

__________________
http://www.twitter.com/0m4r

08-12-2004 17:24
Click Here to See the Profile for 0m4r Click Here to See the Blog of 0m4r Click here to Send 0m4r a Private Message Find more posts by 0m4r Add 0m4r to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
zeus
- mr. groove -

User info:
Registered: Sep 2004
Posts: 480 (0.06 al dì)
Location: Milano
Corso: Com Dig
Anno: Doctor
Time Online: 4 Days, 20:34:17 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

yes....

String s, st;
StringBuffer str;
int lungs, lungst, lung;

video.println();
video.println("Inserisci due stringhe:");
video.println();
video.println();
video.println("Inserisci la prima stringa");
s = key.readLine();
lungs = s.length();
video.println();
video.println("Inserisci la seconda stringa");
st = key.readLine();
lungst = st.length();
video.println();
video.println();
lung = lungs + lungst;
str = new StringBuffer(lung);

for (int i = 0 ; i < lungs ; i++)
str.setCharAt(i, s.charAt(i));

// for (int i = lungs ; i < lungst ; i++)
// str.setCharAt(i, st.charAt(i));

video.println("Stringa concatenata: "+str);


il codice, ovviamente è temporaneo, ma mi dà già errore nel primo ciclo su charAt (il secondo non andrebbe cmq... va ovviamente cambiato)


thx :roll:

__________________
-- spammopoco --

08-12-2004 18:43
Click Here to See the Profile for zeus Click here to Send zeus a Private Message Find more posts by zeus Add zeus to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
zeus
- mr. groove -

User info:
Registered: Sep 2004
Posts: 480 (0.06 al dì)
Location: Milano
Corso: Com Dig
Anno: Doctor
Time Online: 4 Days, 20:34:17 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

ho trovato l'errore.....

il costruttore di stringBuffer scritto in quel modo va in conflitto con charAt. Non ho idea del motivo, cmq adesso ho utilizzato il metodo setLength come avevi fatto tu e sembra funzionare.

Thx anyway

:)

__________________
-- spammopoco --

08-12-2004 18:48
Click Here to See the Profile for zeus Click here to Send zeus a Private Message Find more posts by zeus Add zeus to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
0m4r
.grande:maestro.

User info:
Registered: Mar 2002
Posts: 7287 (0.84 al dì)
Location: Düsseldorf (DE)
Corso:
Anno: ESAMI FINITI
Time Online: 49 Days, 0:57:33 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by zeus
ho trovato l'errore.....

il costruttore di stringBuffer scritto in quel modo va in conflitto con charAt. Non ho idea del motivo, cmq adesso ho utilizzato il metodo setLength come avevi fatto tu e sembra funzionare.

Thx anyway

:)


il costruttore StringBuffer(int i ) ho notato anche io che non funziona come deve. Probabilmete è un bug, non redo proprio che sia un "conflitto" con charAt....

http://bugs.sun.com/bugdatabase/vie...?bug_id=4822952

__________________
http://www.twitter.com/0m4r

08-12-2004 19:00
Click Here to See the Profile for 0m4r Click Here to See the Blog of 0m4r Click here to Send 0m4r a Private Message Find more posts by 0m4r Add 0m4r to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
BodomChild
.precettore.

User info:
Registered: Nov 2004
Posts: 95 (0.01 al dì)
Location: Prov(MI)
Corso: Comunicazione Digitale
Anno: III°
Time Online: 14:29:14 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Idem ho avuto problemi anch'io nello scrivere il codice in quel modo.
Ho trovato molto comoda una situazione di questo tipo:

code:
String testo="Testo"; StringBuffer pippo= new StringBuffer(); for(int i=0;i<testo.length();i++){ pippo.setLength(i+1); pippo.setCharAt(i,testo.charAt(i)); }


ossia setto la lunghezza di pippo ogni volta che gli aggiungo un carattere.

__________________
http://www.poseidon-official.com

09-12-2004 09:42
Click Here to See the Profile for BodomChild Click here to Send BodomChild a Private Message Visit BodomChild's homepage! Find more posts by BodomChild Add BodomChild to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
0m4r
.grande:maestro.

User info:
Registered: Mar 2002
Posts: 7287 (0.84 al dì)
Location: Düsseldorf (DE)
Corso:
Anno: ESAMI FINITI
Time Online: 49 Days, 0:57:33 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

scusa, ma tu la lunghezza di pippo la conosci a priori dato che le due stringhe da concatenare sono inserite dall'utente prima del processo di concatenamento... quindi forse ha più senso settare pippo direttamente alla lunghezza che ti interessa no?

__________________
http://www.twitter.com/0m4r

09-12-2004 14:47
Click Here to See the Profile for 0m4r Click Here to See the Blog of 0m4r Click here to Send 0m4r a Private Message Find more posts by 0m4r Add 0m4r to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
BodomChild
.precettore.

User info:
Registered: Nov 2004
Posts: 95 (0.01 al dì)
Location: Prov(MI)
Corso: Comunicazione Digitale
Anno: III°
Time Online: 14:29:14 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by 0m4r
scusa, ma tu la lunghezza di pippo la conosci a priori dato che le due stringhe da concatenare sono inserite dall'utente prima del processo di concatenamento... quindi forse ha più senso settare pippo direttamente alla lunghezza che ti interessa no?


Beh per l'esercizio che chiedeva di concatenare le 2 stringhe sicuramente.Ho trovato comodo,invece, l'utilizzo di qel codice con il conteggio e verifica d'esistenza delle parole nell'array,dell'esericzio successivo e utilizzando sempre la stessa variabile pippo che si riempiva e cancellava ad ogni verifica, cosi si e' reso dinamico tutto il procedimento. Se settavo la lunghezza della parola a priori, avevo un eccezione alla fine.
In ogni caso, c'e' sempre piu' di una soluzione ad ogni problema. Basta essere sempre consapevole dell'esito.

__________________
http://www.poseidon-official.com

09-12-2004 18:52
Click Here to See the Profile for BodomChild Click here to Send BodomChild a Private Message Visit BodomChild's homepage! Find more posts by BodomChild Add BodomChild to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
0m4r
.grande:maestro.

User info:
Registered: Mar 2002
Posts: 7287 (0.84 al dì)
Location: Düsseldorf (DE)
Corso:
Anno: ESAMI FINITI
Time Online: 49 Days, 0:57:33 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by BodomChild
Beh per l'esercizio che chiedeva di concatenare le 2 stringhe sicuramente.Ho trovato comodo,invece, l'utilizzo di qel codice con il conteggio e verifica d'esistenza delle parole nell'array,dell'esericzio successivo e utilizzando sempre la stessa variabile pippo che si riempiva e cancellava ad ogni verifica, cosi si e' reso dinamico tutto il procedimento. Se settavo la lunghezza della parola a priori, avevo un eccezione alla fine.
In ogni caso, c'e' sempre piu' di una soluzione ad ogni problema. Basta essere sempre consapevole dell'esito.


non ho capito che cosa hai fatto per l'esercizio successivo. Potresti spiegarti meglio, non per copiarti è, tanto io sti esercizio nanche li devo fare, è solo per curiosità....

__________________
http://www.twitter.com/0m4r

09-12-2004 19:07
Click Here to See the Profile for 0m4r Click Here to See the Blog of 0m4r Click here to Send 0m4r a Private Message Find more posts by 0m4r Add 0m4r to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
BodomChild
.precettore.

User info:
Registered: Nov 2004
Posts: 95 (0.01 al dì)
Location: Prov(MI)
Corso: Comunicazione Digitale
Anno: III°
Time Online: 14:29:14 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

parlo dell'esercizio in cui tramite 2 array conti il numero di parole uguali nella stessa frase.
In pratica in poche parole riempio uno stringbuffer fin quando non trovo uno spazio o un punto o una virgola. Quando lo stringbuffer contiene la parola, vedo se esiste gia nell'array che contiene le parole. se esiste allora aggiungo +=1 all'array che tiene i contatori delle parole, se no aggiungo la parola nell'arayd delle parole. le posizioni dell'array tra parole e contatori sono uguali ad esempio: parole[3] contiene "ciao" contatore[3] conterra' il numero delle volte in cui "ciao" e' scritto nella frase.
Ovviamente lo stringbuffer e' uno e uno soltanto che finisce di riempirsi quando trova uno spazio o virgola o punto, e si svuota ogni volta che la parola esiste nell'array oppure viene aggiunta.
Spero di esser stato comprensibile.
notte notte

__________________
http://www.poseidon-official.com

10-12-2004 00:12
Click Here to See the Profile for BodomChild Click here to Send BodomChild a Private Message Visit BodomChild's homepage! Find more posts by BodomChild Add BodomChild to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
nastanada
.arcimaestro.

User info:
Registered: Mar 2004
Posts: 444 (0.06 al dì)
Location: monza
Corso: TICOM
Anno: secondo (quinto?!?!!?)
Time Online: 4 Days, 8:08:26 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

wow i nuovi esercizi sono solo 2! un po' "stellari" ma sono 2!

__________________

MaIL-Me

__________________

10-12-2004 13:03
Click Here to See the Profile for nastanada Click Here to See the Blog of nastanada Click here to Send nastanada a Private Message Find more posts by nastanada Add nastanada to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
zeus
- mr. groove -

User info:
Registered: Sep 2004
Posts: 480 (0.06 al dì)
Location: Milano
Corso: Com Dig
Anno: Doctor
Time Online: 4 Days, 20:34:17 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

ehm....

io ne vedo 3....



:?

__________________
-- spammopoco --

10-12-2004 13:24
Click Here to See the Profile for zeus Click here to Send zeus a Private Message Find more posts by zeus Add zeus to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
BodomChild
.precettore.

User info:
Registered: Nov 2004
Posts: 95 (0.01 al dì)
Location: Prov(MI)
Corso: Comunicazione Digitale
Anno: III°
Time Online: 14:29:14 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by zeus
ehm....

io ne vedo 3....



:?


Se clicchi sull'esercizio delle equazioni di secondo gradi c'e' scritto. Non fare questo esercizio.

__________________
http://www.poseidon-official.com

10-12-2004 15:13
Click Here to See the Profile for BodomChild Click here to Send BodomChild a Private Message Visit BodomChild's homepage! Find more posts by BodomChild Add BodomChild to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
zeus
- mr. groove -

User info:
Registered: Sep 2004
Posts: 480 (0.06 al dì)
Location: Milano
Corso: Com Dig
Anno: Doctor
Time Online: 4 Days, 20:34:17 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

sto diventando cieco....

Off-Topic:
:pc: :saw:


:uhmehehe:

thx

__________________
-- spammopoco --

10-12-2004 15:44
Click Here to See the Profile for zeus Click here to Send zeus a Private Message Find more posts by zeus Add zeus to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
zeus
- mr. groove -

User info:
Registered: Sep 2004
Posts: 480 (0.06 al dì)
Location: Milano
Corso: Com Dig
Anno: Doctor
Time Online: 4 Days, 20:34:17 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Scusate se rompo ancora le p....

Ho avuto un casino di problemi con StringBuffer.... ho svolto l'esercizio della stringa da convertire ma non funziona... continua a darmi errore IndexOutofBounds....

Io lascio il codice, se qualcuno mi sa dire qual'è l'errore gli sarei grato.

--------------------------------------------------------------------------------

ConsoleOutputManager video = new ConsoleOutputManager();
ConsoleInputManager key = new ConsoleInputManager();
char c;
String st;
StringBuffer s = new StringBuffer();
int lust;

video.println();
video.print("Inserisci una stringa");
st = key.readLine();
lust = st.length();
s.setLength(lust);
video.println();

for (int i = 0; i <= lust; i ++) {
c = st.charAt(i);

if (Character.isLowerCase(c)) {
Character.toUpperCas(c);
s.setCharAt(i,c);
} else {
Character.toLowerCase(c);
s.setCharAt(i,c);
}
}

video.println("Stringa cambiata: "+s);
video.println();

-----------------------------------------------------------------------------------

Ho provato a togliere setLength ma l'errore, pur con messaggio lievemente differente, appare ugualmente.


Help... thx

__________________
-- spammopoco --

10-12-2004 16:04
Click Here to See the Profile for zeus Click here to Send zeus a Private Message Find more posts by zeus Add zeus to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 09:05.    Post New Thread    Post A Reply
Pages (5): « 1 [2] 3 4 5 »   Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread | Add to Bookmarks

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
 

Powered by: vBulletin v2.3.1 - Copyright ©2000 - 2002, Jelsoft Enterprises Limited
Mantained by dsy crew (email) | Collabora con noi | Segnalaci un bug | Archive | Regolamento | Licenze | Thanks | Syndacate
Pagina generata in 0.064 seconds (73.08% PHP - 26.92% MySQL) con 23 query.