I’ve been using python too much lately and I forget if there’s a way to do this in Java:
print "I am a %s" % string
I googled, but it’s hard to find simple stuff like this when you don’t know exactly what this is called in each language.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Two possible simple ways of doing it:
or
Notice that the
printf()will not print a newline, so you have to add it manually (“\n”). But (thanks to BalusC), you can also use"%n"in your format. It will be replaced by the default system newline character. (So:String.format("I am a %s%n", yourString))Both prints
I am a human\n.In Java, it is called
formatting. Take also a look atString.format().