Why doesn’t the printf concatenate?

Asked

Viewed 263 times

-8

I’m an innovator in Java and I’m in trouble because printf does not concatenate two quantiles with a variable, since the println let me work with decimals but it doesn’t 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);
}
  • 1

    Translate your question. Healing your problem, to concatenate you to use the sign of More ( + ) and not Comma ( , ) ... "priority =% .2f% n" + this.value Query + "\ ndespense 20.00"

  • 1

    Welcome to Stackoverflow in English. If you want to Ask questions in English go to https://stackoverflow.com/, or Translate your Question

  • I translated "two mounts" as "two amounts", but I don’t know if that would be the best translation in your case.

  • 1

    I found the term "innovative in Java" very strange, and when I saw in the original text I found it even more strange.O

  • 2

    @Jeffersonquesado If he is an innovator in Java, then I wonder what I would be.

1 answer

3

Your code does not compile for several reasons:

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

  2. You do not close the string that starts with "xonvenio. By the way, I think you’re talking about "covenant", and not of "xonvenio".

  3. You are using system lower case letter instead of System capital letter.

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

  5. That \ n shouldn’t have a space in the middle.

  6. Your format string "priority =% .2f% n" is poorly formed.

And really, printf does not concatenate anything, the reason is that printf is not a concatenation method, but a method for putting data into a text model.

How about your statement that println not working with decimals, she’s wrong. Your problem is actually that they don’t come formatted as you want, which is something completely different. The solution would be to format them properly before.

Unfortunately, you don’t understand basic concepts about Java. So, don’t dare call yourself a Java innovator until you are able to master the basics of the language.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.