+1 Neil Cannon · March 14, 2015
Videos 38, 39, 40.

return String.format("%02d:%02d:%02d: %s",getHour(), getMinute(), getSecond());

When I try to use String. format in the java videos instead of getting String.format (args1, args2),

I get  String.format (format, args)?

Can anyone explain?

Post a Reply


Oldest  Newest  Rating
0 Dol Lod · March 15, 2015
The %d means to substitute an integer value, %s means to substitute a string value.


String word="planet";
int i=8;
String.format("There are %d %s in the universe,i,word);
This would perform a substitution of the corresponding values. The int is converted to its string equivalent and then replaces the %d.

The %s is replaced directly by the string.

Another way to think of % is that it tells the compiler to think of it as a placeholder where the letter following the percent specifies what data type it is a placeholder for. Ex. %f would mean floating point. 

If the string were to be outputted, it would say "There are 8 planets in the universe". 
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator