Why does printf not concatenate? [closed]

-8

I'm an innovator in Java and I'm having problems because printf does not concatenate two amounts with a variable, since println lets me work with decimals but does not work with them. See:

if (this.consulta == "health plan") {
    system.out.printf ("priority =% .2f% n", this.value Query, "\ ndespense 20.00");
}
else {
    system.out.printf ("xonvenio, this.valorConsulta);
}
    
asked by anonymous 01.11.2017 / 23:18

1 answer

3

Your code does not compile for several reasons:

  • You use commas to concatenate. You should use + .

  • You do not close the string that starts with "xonvenio . In fact, I think you are talking about " covenant", not " xonvenio ".

  • You are using system with lowercase letter instead of System with uppercase.

  • Compare strings with == will not do what you want.

  • That \ n should not have a space in between.

  • Your format string "priority =% .2f% n" is malformed.

  • And actually, printf does not concatenate anything, the reason is printf is not a concatenation method, but a method to put data into a text template.

    As for this statement that println does not work with decimals, it is wrong. Your problem is actually that they do not come as formatted as you want, which is something completely different. The solution would be to format them properly before.

    Unfortunately, you have not mastered Java basics. So, do not you dare call yourself an innovator in Java as long as you are not able to master the basics of language.

        
    02.11.2017 / 13:42