Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
Cómo devolver String.format con matrices

Cuando imprimo una instancia de mi clase, se hace referencia a la instancia como "nula" porque devuelvo "nula", ¿cómo puedo formatear la clase toString para que devuelva lo que realmente escribí en esta función?

 public String toString() { System.out.print(this.coefficient); for(int i=0; i<26;i++) { if(degrees[i] == 1) { System.out.print(variables[i]); } if(degrees[i]>1) { System.out.print(variables[i] + "^" + degrees[i]); } } System.out.println('\n'); return null; }

Por ejemplo, tiene que devolver "m1 = 13a^2b^3" (es un polinomio) pero en su lugar devuelve "13a^2b^3 m1 = null"

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

En lugar de imprimir directamente cada componente del String , concatenelos usando un StringBuilder :

 public String toString() { StringBuilder s = new StringBuilder(); s.append(this.coefficient); for (int i = 0; i < 26; i++) { if (degrees[i] == 1) { s.append(variables[i]); } else if (degrees[i] > 1) { s.append(variables[i]).append('^').append(degrees[i]); } } return s.toString(); }
over 4 years ago · Santiago Trujillo Report

0

Utilice el generador de cadenas. Dondequiera que esté usando System.out.println

En vez de eso

 StringBuilder temp=new StringBuilder(); temp.append();// Add here the content what you are printing with Sysout // at the end return temp.toString();
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!