How to end a while Loop via user input

前端 未结 5 366
深忆病人
深忆病人 2021-01-22 18:42
package cst150zzhw4_worst;

import java.util.Scanner;

public class CST150zzHW4_worst {

    public static void main(String[] args) {
    //Initialize Variables
    doub         


        
5条回答
  •  清酒与你
    2021-01-22 18:56

    You just need to set repeat to true or false based on user input. So in the end, compare input with yes or no. Something like this would work for you :

    if ("yes".equals(input)) 
     repeat = true; // This would continue the loop
    else 
     repeat = false; // This would break the infinite while loop 
    

提交回复
热议问题