java - I'm using toString method, but it doesn't give me the format I want? -


i want method return rectangle base(coordinates) height , width.

an example

for rectangle lower left corner located @ (-3, 2) , having width of 4 , height of 5, method should return “base: (-3,2) w:4 h:5”. example, there single space @ location 5, 12, , 16.

//left = x, bottom =y , width = w, height = h

this method have

public string tostring(){     return string.format("%-5s%-12s%16d","base:" ,"(",this.left,",", this.bottom,")", "w:",this.width, "h:",this.height); } 

there coalition between number of format specifiers , number of parameters, should equal in quality.

something string.format("%-5s(%d, %d) w:%d h:%d","base:", left, bottom, width, height) print base:(-3, 2) w:4 h:5 ... based on values have provided

the format specifiers based on c, have @ these examples more details


Comments