Java if/for loop assistance -


below code...i trying make countdown timer. right works correctly in terms of counting down in correct sequential order. trying figure out how place if statement within code prints 1 minute , ''seconds, instead of 1 minutes , '' seconds

import java.util.scanner;  public class countdown {  public static void main(string[] args) {      scanner scan = new scanner(system.in);     int minutes;     system.out.println("please enter timer countdown in minutes:");     minutes = scan.nextint();      while (minutes < 1) {         system.out.print("invalid entry: enter 1 or more minutes: ");         minutes = scan.nextint();     }     (int = minutes - 1; >= 0; i--)      {         (int s = 59; s >= 1; s--)              system.out.println(i + " minutes, " + s + " seconds");         system.out.println("the timer done!");      }  } 

}

just add if/else statement in there:

for (int = minutes - 1; >= 0; i--){     string minute;     if(minutes == 1)         minute = " minute ";     else         minute = " minutes ";      (int s = 59; s >= 1; s--){         string seconds;         if(s == 1)             seconds = " second";         else             seconds = " second";         system.out.println(i + minute + s + seconds);     } } 

the other answer better, uses different syntax makes code short line. same thing.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -