Do while loop not working? (Cannot find variable)

前端 未结 3 375
借酒劲吻你
借酒劲吻你 2021-01-29 08:43

I am having trouble with my do while loop not finding my variable to test if the condition is true or not. Here is my code:

import java.util.Scanner;
public clas         


        
3条回答
  •  感情败类
    2021-01-29 08:47

    play must be declared before the do-while loop in order to be in scope of the while condition.

    String play = "";
    do {
        ...
        play = prompt.next();
    } while(play.equalsIgnoreCase("yes"));
    

提交回复
热议问题