2020-11-27
作者:互联网
基本游戏循环
import java.util.Scanner;
public class demon {
public static void main(String[] args) {
System.out.println("程序开始...");
Scanner ipt = new Scanner(System.in);
System.out.println("是否要开始游戏?");
String choice = ipt.next();
while (choice.equals("y")) {
System.out.println("重复的内容");
System.out.println("是否要开始游戏?");
choice = ipt.next();
}
System.out.println("程序结束...");
}
}
指定次数的游戏循环
import java.util.Scanner;
public class demon {
public static void main(String[] args) {
System.out.println("程序开始...");
Scanner ipt = new Scanner(System.in);
System.out.println("是否要开始游戏?");
String choice = ipt.next();
int counter = 3;
while (choice.equals("y") && counter > 0) {
counter--;
System.out.println("还可以玩" + counter + "次");
System.out.println("重复的内容");
System.out.println("是否要开始游戏?");
choice = ipt.next();
}
System.out.println("程序结束...");
}
}
标签:11,27,Scanner,System,choice,2020,ipt,println,out 来源: https://blog.csdn.net/Gongjs123/article/details/110228725