How to repeat/loop/return to a class

前端 未结 4 1010
独厮守ぢ
独厮守ぢ 2021-01-28 02:22

Im a beginner with java and i am following tutorials by Thenewboston on youtube. I wanted to go to a bit more advanced (in my opinion... but not really) things. So heres the c

4条回答
  •  心在旅途
    2021-01-28 03:04

    Wrap your code around while loop and use break to come out of loop if your condition is true.

    while((alex.hasNext()))
       {
        test = alex.nextDouble();
    
        if (test == 9){
            System.out.println("eat");
            break;
    
    }else{
            System.out.println("do not eat");
    
    
    }
       }
    

提交回复
热议问题