所以我的布尔方法运行并返回正确的真或假......但我需要某种扫描仪函数来获取返回的内容以遵循 if 语句。这是我的主要代码。任何帮助表示赞赏!另外,我的柜台不工作:(我是新来的。
import java.util.Random;
import java.util.Scanner;
public class CrapsP5 {
public static void main(String[] args) {
int number = 0, total, counter;
total = counter = 0;
String response;
Scanner console = new Scanner(System. in );
//1
System.out.println("Would you like to play craps? (Y/N)");
response = console.next();
if (response.equalsIgnoreCase("N")) {
System.exit(0);
}
//2
System.out.println("Welcome to craps. Would you like to see the rules? (Y/N)");
response = console.next();
if (response.equalsIgnoreCase("Y")) {
rules();
}
//3 call play method
play();
//I need something here to act like the scanner console does?? yes?? but what?
if (true) {
System.out.println("Congrats! You've won!");
counter++; //add 1 to win count (w)
total = counter;
play();
}
if (false) {
System.out.println("I'm sorry, you've lost.");
System.exit(0);
}
//4
System.out.println("Thanks for playing! You won " + total + " number of times before losing.");