[Solved] declaring and assigning variable [closed]


Instead of writing the following which id not valid Java,

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

perhaps you intended to write

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

However a much cleaner way to do this is to pass a String to the constructor

  Paraula tipo1 = new Paraula("t1");

Where your constructor is

public Paraula(String s) {
    lletres = s.toCharArray();
    llargaria = lletres.length;
}

solved declaring and assigning variable [closed]