Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
369 views
in Technique[技术] by (71.8m points)

java.util.scanner - scanner input that can stop loop anytime?

I'm basically making a clock and I want a specific input to be able to stop it. any ideas?

here's my code:

  public static void main(String[] args) {
  ...
  Scanner input = new Scanner(System.in);
  ...  
  int s = 0;
  int m = 0;
  int h = 0;
  clock: // label to break a outer most loop 
  for(int i = 0; i<2; i++) {
          on = Boolean.parseBoolean(onValue[i]);
          while (on = true) {
                for (i=1;  i<=60; i++) {
                        s++;
                        if(input2check.compareTo("") == 0) {
                            on = Boolean.parseBoolean(onValue[1]);
                            break clock;
                          }
                            if (s == 60) {
                              s = 0;
                            }
                  System.out.println(s + " sec" );
                  }
          }
    }
}  
question from:https://stackoverflow.com/questions/65874764/scanner-input-that-can-stop-loop-anytime

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...