package day141018;
/**
*
* 21根火柴,每次选择1-4根火柴(人先取,最后保证电脑胜利)
* @author XWJ
*/
import java.util.Scanner;
public class Match21 {
public static void main(String[] args) {
Scanner N = new Scanner(System.in);
int total = 21, total2 = 21;
while (total > 1) {
System.out.print("请输入您要抽取的火柴数量:");
int hum = N.nextInt();
int com;
if (1 <= hum || hum <= 4) {
com = 5 - hum;
System.out.printf("电脑抽取的火柴数量为:%d\n", com);
total = total - com - hum;
total2 = total - hum;
System.out.printf("剩余火柴数量为:%d\n", total);
if (total2 == 1) {
System.out.printf("玩家胜利!");
} else if (total == 1) {
System.out.printf("庄家胜利!");
}
}
}
N.close();
}
}
/**
*
* 21根火柴,每次选择1-4根火柴(人先取,最后保证电脑胜利)
* @author XWJ
*/
import java.util.Scanner;
public class Match21 {
public static void main(String[] args) {
Scanner N = new Scanner(System.in);
int total = 21, total2 = 21;
while (total > 1) {
System.out.print("请输入您要抽取的火柴数量:");
int hum = N.nextInt();
int com;
if (1 <= hum || hum <= 4) {
com = 5 - hum;
System.out.printf("电脑抽取的火柴数量为:%d\n", com);
total = total - com - hum;
total2 = total - hum;
System.out.printf("剩余火柴数量为:%d\n", total);
if (total2 == 1) {
System.out.printf("玩家胜利!");
} else if (total == 1) {
System.out.printf("庄家胜利!");
}
}
}
N.close();
}
}