Hi! Iīm fairly new, and I havenīt figured out how to put both variables and text in the same place. ( sorry for my english ). Let me demonstrate.
Letīs say I want command prompt to show a message "You have spent x euros and gained y profit." , where x and y are variables.
the only way i know how to accomplish this is:
System.out.printf("You have spent ");
System.out.printf("%1$.2f", x);
System.out.printf("euros and gained ")
and so on. as you can see even though it works fine, itīs a very stupid way of doing this. I had something like this in mind:
System.out.printf("%1$.2f", "You have spent", x, "euros and gained", y, "profit");
but this way of writing it is incorrect. Can someone please show me the correct way of doing this?
Help is much appreciated