MethodBlogsTest.java 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package com.sf;
  2. import java.util.Scanner;
  3. public class MethodBlogsTest {
  4. /**
  5. * 猜拳游戏 1 石头 2 剪刀 3 布
  6. */
  7. public static void main(String[] args) {
  8. System.out.println("游戏开始啦");
  9. Scanner scanner = new Scanner(System.in);
  10. int comIntegral = 0;
  11. int playIntegral = 0;
  12. while (comIntegral <5 | playIntegral < 5){
  13. //随机生成电脑数
  14. int com = (int) (Math.random()*3+1);
  15. //人的数
  16. int player = scanner.nextInt();
  17. if(player == 886){
  18. break;
  19. }
  20. if(player >0 & player <4){
  21. if(player != com){
  22. if(player - com == -1 | player - com == 2){
  23. playIntegral +=1;
  24. }else {
  25. comIntegral +=1;
  26. }
  27. }else {
  28. System.out.println("默契");
  29. }
  30. }else {
  31. System.out.println("输入有误");
  32. }
  33. }
  34. }
  35. }