java - declaring and assigning variable -


this class has variable called paraula , i'm having trouble when assign value it.

public paraula() { lletres = new char[maxim]; llargaria = 0; }  public static paraula llegir() { paraula nova = new paraula(); botarblancs(); while ((lletra != fisequencia) && // no ha acabat la seqüència         (lletra != blanc)) { // hi ha prou espai     nova.lletres[nova.llargaria++] = lletra;     lletra = leercarteclado(); } return nova; }  public string tostring() { string msg = ""; (int idx = 0; idx < llargaria; idx++) {     msg += lletres[idx]; } return msg; }  public boolean esiguala(paraula b) { boolean iguals = llargaria == b.llargaria; (int idx = 0; (idx < llargaria) && iguals; idx++) {     iguals = lletres[idx] == b.lletres[idx]; } return iguals; }  public static boolean iguals(paraula a, paraula b) { return a.esiguala(b); }  public boolean buida() { return llargaria == 0; }  public static void botarblancs() { while (lletra == blanc) {     lletra = leercarteclado(); } }  public static void botarparaula() throws exception { while ((lletra != '.') && (lletra != blanc)) {     lletra = leercarteclado(); } } static public char leercarteclado() { char res = '.'; if (frase != null) {     res = frase[indice++]; } return res; } 

i want declare 2 paraula variables called: tipo (using method llegir() reads sequence of characters) , tipo1:

paraula tipo;         tipo = paraula.llegir();                paraula tipo1;               tipo1  = {                  paraula.lletres[0] = 't';               paraula.lletres[1]='1';               paraula.llargaria = 2;        } 

when declare tipo1 reports illegal start of expression. what's wrong code?

thank you!

instead of writing following id not valid java,

          paraula tipo1;           tipo1  = {              paraula.lletres[0] = 't';           paraula.lletres[1]='1';           paraula.llargaria = 2; 

perhaps intended write

          paraula tipo1 = new paraula();           tipo1.lletres[0] = 't';           tipo1.lletres[1]='1';           tipo1.llargaria = 2; 

however cleaner way pass string constructor

  paraula tipo1 = new paraula("t1"); 

where constructor is

public paraula(string s) {     lletres = s.tochararray();     llargaria = lletres.length; } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -