function to return a string in java
<p>I wrote the following function to convert a time in milliseconds to a string of the format mins:seconds. Being a former C programmer I assumed that "ans" would have to be static in order to work properly, but putting static before String appears to not be allowed. </p>

<p>My question is - will this function work - and if not, what change will make it work.</p>

<pre><code>public String time_to_string(long t) // time in milliseconds
{
    String ans;
    int mins,secs;
    if (t &lt; 0)
    {
        return "-";
    }
    else
    {
        secs = (int)(t/1000);
        mins = secs/60;
        secs = secs - (mins * 60);

        ans = ""+mins+":"+String.format("%02d", secs);

        return ans;
    }
}
</code></pre>
