if (sum < 6) {
System.out.println("You win");
System.out.println();
// Does the user want to retry?
System.out.print("Would you like to retry?(Y or N) : ");
String retry = input.nextLine();
while (true) {
// If they say y or Y, roll again
if (("y".equals(retry)) || ("Y".equals(retry))) {
roll();
// Check for anything other than y and Y
} else if (("n".equals(retry)) || ("N".equals(retry))) {
System.out.println("Closing");
break;
} else if (!("y".equals(retry)) || !("Y".equals(retry))) {
System.out.print("Invalid input. Would you like to retry?(Y or N) …Run Code Online (Sandbox Code Playgroud) 我试图让我的游戏给出用户成绩的百分比(%),但我一直得到0%.
这是我的代码:
int win = 2
int Percentage = win/5;
System.out.println();
System.out.println("Your score is : " + win + "/" + "5" + "(" + Percentage *100 + "%" + ")");
Run Code Online (Sandbox Code Playgroud)
控制台:Your score is : 2/5(0%)