what is %s mean in java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

what is %s mean in java

what is %s ?

20th May 2019, 4:25 AM
Tzion
Tzion - avatar
2 Answers
+ 3
With integer types, % is the modulus operator.  In your example, it is a placeholder character. It means when % is encountered, the next character determines how to interpret the argument and insert it into the printed result.  %s means interpret as string, %d is for digit, %x is digit in hexadecimal, %f is for float, etc....  It doesn't really 'do' anything, it's just a convention used for formatting text..
20th May 2019, 4:29 AM
Troy🌹
Troy🌹 - avatar
+ 2
It can be used with printf, and it works like this: String s = "string"; System.out.printf("Here is a string: %s", s); Output: Here is a string: string %s means a string is going to be used here
20th May 2019, 4:30 AM
Airree
Airree - avatar