import java.util.*;
class token {
public static void main(String args[]){
Scanner input = new Scanner(System.in);
Random number = new Random();
System.out.println("Do you want to play again(y/n)? ");
String in = input.nextLine();
do{
int num1,num2,sum;
num1 = 1+number.nextInt(6);
num2 = 1+number.nextInt(6);
sum = num1 + num2;
System.out.print("Dice 1: "+num1);
System.out.print("\nDice 2: "+num2);
System.out.print("\nSum: "+sum);
if(sum%2==1){
System.out.println("\nYou have lost 1 token.");
}else if(sum>10){
System.out.println("\nYou have won 2 tokens.");
}else if(sum>11){
System.out.println("\nYou have won 2 tokens.");
}else if(sum>12){
System.out.println("\nYou have won 2 tokens.");
}else{
System.out.println("\nYou have won 1 token.");
}
System.out.println("Do you want to play again(y/n)? ");
String in1 = input.nextLine();
}while(in == "y");
}
}
所以我尝试使用 do while 循环,但不幸的是,它根本不循环。示例输出:你想再玩一次吗(y/n)? y 骰子 1:3 骰子 2:4 总和:7 您丢失了 1 个令牌。你想再玩一次吗(y/n)? 是的
我希望我的程序不断循环,除非用户输入 n。