title: Extra outputs in a program to when using method overloading
body: <p>I am making a program in which there are two methods of the same name using method overloading, specifics:-</p>
  
  <p>1st method:- Name-getDurationString
               Parameters-minutes(check if >=0) and second(check >=0 and 
                                                                    &lt;=59)
               if TRUE, convert minutes and seconds into their equivalent 
               hours, minutes and seconds and return a string in a format 
               "XX"h "YY"m "ZZ"s.</p>
  
  <p>if FALSE, return a string "invalid value"</p>
  
  <p>2nd method:- Name-getDurationString
               Parameters-seconds(check if >=0)
               if TRUE, convert seconds into their equivalent 
               minutes and seconds and return a string in a format 
               "YY"m "ZZ"s. Also, call the 1st method with the corrected 
               minutes and seconds.</p>
  
  <p>if FALSE, return a string "invalid value"</p>
  
  <p>Call both the methods from the main method.</p>
  
  <p>Problem:- When running the code, instead of getting 3 outputs, I get 5.</p>
  
  <pre><code>public class MinutesAndSeconds {
  
  public static void main(String[] args){
      getDurationString(120,58);
      getDurationString((7200));
  }
  
  public static  String getDurationString(int minutes,int seconds){
      if(minutes&gt;=0 &amp;&amp; seconds&gt;=0 &amp;&amp; seconds&lt;=59){
          int hours=minutes/60;
          int remaingMinutes=(minutes%60);
          String i = hours + " h " + remaingMinutes + " m " + seconds +" s";
          System.out.println(i);
          return i;
      }
      else return "invalid value";
  
  }
  
  // 2nd method(overloading)
  public static  String getDurationString(int seconds){
      if(seconds&gt;=0){
          int correctedMinutes=(seconds/60);
          int correctedSeconds=seconds%60;
          String i = correctedMinutes + " m " + correctedSeconds + " s";
          System.out.println(i+"\n"+getDurationString(correctedMinutes,correctedSeconds));
  
          return (i+"\n"+getDurationString(correctedMinutes,correctedSeconds));
      }
      else return "invalid value";
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Expected:-
  **</p>
  
  <ul>
  <li>2 h 0 m 58 s </li>
  <li>120 m 0 s  </li>
  <li>2 h 0 m 0 s</li>
  </ul>
  
  <p>**</p>
  
  <p>Actual:-</p>
  
  <ul>
  <li>2 h 0 m 58 s</li>
  <li>2 h 0 m 0 s</li>
  <li>120 m 0 s</li>
  <li>2 h 0 m 0 s</li>
  <li>2 h 0 m 0 s</li>
  </ul>