From fb32cd86c87ed1eddf72ca91b114b040be67c81f Mon Sep 17 00:00:00 2001 From: TTN <2298440591@qq.com> Date: Wed, 21 Feb 2024 15:29:35 +0800 Subject: [PATCH] Guess-number --- project/Guess-number/Leonhard.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 project/Guess-number/Leonhard.java diff --git a/project/Guess-number/Leonhard.java b/project/Guess-number/Leonhard.java new file mode 100644 index 0000000..08392bb --- /dev/null +++ b/project/Guess-number/Leonhard.java @@ -0,0 +1,25 @@ +import java.util.Random; +import java.util.Scanner; +public class Main { + public static void main(String[] args) { + Random r =new Random(); + int number=r.nextInt(100)+1; + while(true) { + System.out.println("请输入你要猜的数字"); + Scanner sc = new Scanner(System.in); + int guessnumber = sc.nextInt(); + + if (guessnumber > number) { + System.out.println("你猜的数字" + guessnumber + "大了"); + + } else if (guessnumber < number) { + System.out.println("你猜的数字" + guessnumber + "小了"); + + } else { + System.out.println("恭喜 你,猜对了"); + break; + } + } + + } +} \ No newline at end of file -- Gitee