java - how to return null to int method -


iam new programming.iam wrking on quiz game software. here want count down printed "3,2,1,go...go...go"

  package t2;  import java.util.scanner; import java.util.timer; import java.util.timertask;  public class stopwatch { static int interval; static timer timer;  public static void main(string[] args) {     scanner sc = new scanner(system.in);     int delay = 1000;     int period = 1000;     timer = new timer();     interval = 3;     system.out.println("3");     timer.scheduleatfixedrate(new timertask() {          public void run() {             system.out.println(setinterval());          }     }, delay, period); }     private static final int setinterval() {     string go="go...go...go";     if (interval == 2)     {          timer.cancel();         return go;     }        return --interval;  } } 

this says setinterval() has int return value.if place system.out.print("go"); in place of return go; prints go , prints 1 out of requirement. please buddy can tell me how this.

change return type of setinterval object take advantage of overloaded println method , conditional should check 1 instead of 2. use print instead of println have output on same line.

private static final object setinterval() {     string go="go...go...go";     if (interval == 1)     {          timer.cancel();         return go;     }     return --interval; } 

full example

 package t2;      import java.util.scanner;     import java.util.timer;     import java.util.timertask;      public class stopwatch {         static int interval;         static timer timer;          public static void main(string[] args) {             scanner sc = new scanner(system.in);             int delay = 1000;             int period = 1000;             timer = new timer();             interval = 3;             system.out.print("3,");             timer.scheduleatfixedrate(new timertask() {                  public void run() {                     system.out.print(setinterval() + ",");                  }             }, delay, period);         }          private static final object setinterval() {             string go = "go...go...go";             if (interval == 1) {                  timer.cancel();                 return go;             }              return --interval;         }     } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -