|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Junior Member
Iscritto dal: Sep 2010
Messaggi: 9
|
[JAvA] questa cosa mia fa disperare!!
Ciao,
ho scritto questo programma per svolgere un esercizio.. import java.util.Scanner; class Dict { private class Pair { public String word; public int count; public Pair(String w, int c) { word = w; count = c; } public String getWord() { return word;} public void setWord(String newword) { word = newword; } public String toString() { return word + " " + count; } } private Pair[] p; private int psize; public Dict() { p = new Pair[1]; psize = 0; } public void insert(Pair x) { if (psize == p.length) { Pair[] pp = new Pair[psize*2]; System.arraycopy(p, 0 , pp, 0 ,psize); p = pp; } for ( int i = 0; i<psize; i++) if ( p[i].getWord().equals(x.getWord())) { p[i].setWord(x.getWord()); return; } p[psize++] = x; psize++; } public Pair find(Pair x) { for ( int i = 0; i<psize; i++) if ( p[i].getWord().equals(x.getWord())) return p[i]; return null; } public String toString() { String s=""; for (int i = 0; i<psize; i++) { s += p[i].toString() + '\n'; } return s; } } public class MainDict { public static void main(String[] args) { Scanner c = new Scanner(System.in); String text = ""; while (c.hasNextLine()) text += c.nextLine() + '\n'; Dict dict = new Dict(); String word = ""; for ( int i = 0; i<text.length(); i++) { char l = text.charAt(i); if (Character.isLetter(l)) word += l; if (word.length()>0) { Pair x = new Pair(word, 1); Pair p = dict.find(x); if ( p != null) p.count++; else dict.insert(x); word = ""; } } System.out.println(dict); } } ma in compilazione mi dà questo errore MainDict.java:69 find(Dict.pair) cannot be applied to (Pair) Pair p = dict.find(x); MainDict.java:73 insert(Dict.pair) cannot be applied to (Pair) dict.insert(x); Sarò stanca, non lo so, ma non riesco a capire il perchè.. ![]() Grazie |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Feb 2002
Città: Trento
Messaggi: 962
|
Mi sembra da quello che hai scritto che il tipo "Pair" è il tipo del parametro del metodo find: in realtà dovrebbe essere "Dict.pair", visto che si tratta di una classe dichiarata internamente alla classe Dict stessa.
Però non sono molto sicuro, perchè il codice è piuttosto intricato: potresti provare a "spezzare" il codice, dichiarando Pair in un file separato, e poi vedere se l'errore di compilazione permane?
__________________
"Et Eärallo Endorenna utúlien. Sinome maruvan ar Hildinyar tenn' Ambar-metta!" -- Aragorn Elessar, Heir of Isildur Mixmar -- OpenSuSE 11.1 on AMD 64 3000+ on DFI LanParty nF4-D | GeForce 6600 GT + Thermaltake Schooner on Samsung 710N Storage -- ( 2 x Hitachi Deskstar 80 Gb + 1 x Hitachi 250 Gb ) = 1 RAID 5 + 1 Storage space LaCie Ethernet Disk Mini 250 Gb | HP - DV2150 EL MILAN CLAN |
![]() |
![]() |
![]() |
#3 |
Junior Member
Iscritto dal: Sep 2010
Messaggi: 9
|
In effetti poi ieri ho fatto esattamente così..e si è sistemato
![]() ![]() |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 20:41.