From 4d2b70a962761755a6ef7ad162a9c1f8885a6e67 Mon Sep 17 00:00:00 2001 From: Jmoon Date: Sat, 20 Jan 2024 16:46:47 +0800 Subject: [PATCH 1/2] =?UTF-8?q?Java-=E7=9F=B3=E5=A4=B4=E5=89=AA=E5=AD=90?= =?UTF-8?q?=E5=B8=83=E5=B0=8F=E6=B8=B8=E6=88=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\203\345\260\217\346\270\270\346\210\217" | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 "\345\245\275\347\216\251\344\275\206\346\262\241\344\273\200\344\271\210\347\224\250\344\273\243\347\240\201/Java-\347\237\263\345\244\264\345\211\252\345\255\220\345\270\203\345\260\217\346\270\270\346\210\217" diff --git "a/\345\245\275\347\216\251\344\275\206\346\262\241\344\273\200\344\271\210\347\224\250\344\273\243\347\240\201/Java-\347\237\263\345\244\264\345\211\252\345\255\220\345\270\203\345\260\217\346\270\270\346\210\217" "b/\345\245\275\347\216\251\344\275\206\346\262\241\344\273\200\344\271\210\347\224\250\344\273\243\347\240\201/Java-\347\237\263\345\244\264\345\211\252\345\255\220\345\270\203\345\260\217\346\270\270\346\210\217" new file mode 100644 index 0000000..4222aa2 --- /dev/null +++ "b/\345\245\275\347\216\251\344\275\206\346\262\241\344\273\200\344\271\210\347\224\250\344\273\243\347\240\201/Java-\347\237\263\345\244\264\345\211\252\345\255\220\345\270\203\345\260\217\346\270\270\346\210\217" @@ -0,0 +1,52 @@ +import java.util.Random; +import java.util.Scanner; +import java.util.concurrent.TimeUnit; + +/** + * 石头剪子布游戏:✌️、✊、🤚 + * 当两人意见出现分歧时,玩石头剪子布的游戏可以帮助做出决策 + * 程序的用法:按下回车出结果 + */ +public class RockPaperScissors { + static boolean flag = true; + + public static void main(String[] args) throws InterruptedException { + + Scanner sc = new Scanner(System.in); + //按回车键终止程序 + new Thread(() -> { + sc.nextLine(); + flag = false; + }).start(); + + //下面这段程序的作用是动态展示A与B的出手 + String[] img = {"✌️", "✊", "🤚"}; + Random random = new Random(); + int a = random.nextInt(3); + int b = random.nextInt(3); + while (flag) { + System.out.print(img[a] + " VS " + img[b] + "\r"); // \r的作用是光标回到行首 + TimeUnit.MILLISECONDS.sleep(10); + a = random.nextInt(3); + b = random.nextInt(3); + } + System.out.println("=================================================="); + System.out.println("[A: " + img[a] + "] VS [" + "B: " + img[b] + "]"); //最终结果 + + /* + * 判断A和B的胜负关系:✌️=0,✊=1,🤚=2,三者是一个循环的关系,即 0 < 1 < 2 < 0 + * 如果B在A左边,那么A获胜 + * 如果B在A右边,那么B获胜 + * 否则是平局 + * */ + int[] choice = {0, 1, 2}; + if (choice[(a + 2) % 3] == choice[b]) { // B在A左边 + System.out.println("A win!"); + } else if (choice[(a + 1) % 3] == choice[b]) { // B在A右边 + System.out.println("B win!"); + } else { + System.out.println("平局!"); + } + + } +} \ No newline at end of file -- Gitee From d5acf7918d025e2821b21cc4cfe4bca6cd1f3aee Mon Sep 17 00:00:00 2001 From: Jmoon Date: Sat, 20 Jan 2024 17:28:22 +0800 Subject: [PATCH 2/2] =?UTF-8?q?Java-=E7=9F=B3=E5=A4=B4=E5=89=AA=E5=AD=90?= =?UTF-8?q?=E5=B8=83=E5=B0=8F=E6=B8=B8=E6=88=8F(update)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\255\220\345\270\203\345\260\217\346\270\270\346\210\217" | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git "a/\345\245\275\347\216\251\344\275\206\346\262\241\344\273\200\344\271\210\347\224\250\344\273\243\347\240\201/Java-\347\237\263\345\244\264\345\211\252\345\255\220\345\270\203\345\260\217\346\270\270\346\210\217" "b/\345\245\275\347\216\251\344\275\206\346\262\241\344\273\200\344\271\210\347\224\250\344\273\243\347\240\201/Java-\347\237\263\345\244\264\345\211\252\345\255\220\345\270\203\345\260\217\346\270\270\346\210\217" index 4222aa2..d1bf874 100644 --- "a/\345\245\275\347\216\251\344\275\206\346\262\241\344\273\200\344\271\210\347\224\250\344\273\243\347\240\201/Java-\347\237\263\345\244\264\345\211\252\345\255\220\345\270\203\345\260\217\346\270\270\346\210\217" +++ "b/\345\245\275\347\216\251\344\275\206\346\262\241\344\273\200\344\271\210\347\224\250\344\273\243\347\240\201/Java-\347\237\263\345\244\264\345\211\252\345\255\220\345\270\203\345\260\217\346\270\270\346\210\217" @@ -39,10 +39,9 @@ public class RockPaperScissors { * 如果B在A右边,那么B获胜 * 否则是平局 * */ - int[] choice = {0, 1, 2}; - if (choice[(a + 2) % 3] == choice[b]) { // B在A左边 + if ((a + 2) % 3 == b) { // B在A左边 System.out.println("A win!"); - } else if (choice[(a + 1) % 3] == choice[b]) { // B在A右边 + } else if ((a + 1) % 3 == b) { // B在A右边 System.out.println("B win!"); } else { System.out.println("平局!"); -- Gitee