{"id":25335,"date":"2024-05-09T14:53:29","date_gmt":"2024-05-09T05:53:29","guid":{"rendered":"http:\/\/www.tyosuke20xx.com\/blog\/?p=25335"},"modified":"2024-05-09T14:53:31","modified_gmt":"2024-05-09T05:53:31","slug":"java-%e6%95%b0%e5%bd%93%e3%81%a6%e3%82%b2%e3%83%bc%e3%83%a0","status":"publish","type":"post","link":"http:\/\/www.tyosuke20xx.com\/blog\/?p=25335","title":{"rendered":"java \u6570\u5f53\u3066\u30b2\u30fc\u30e0"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>import java.util.Scanner;\n\npublic class Main {\n    public static void main(String&#91;] args) {\n        Scanner scanner = new Scanner(System.in);\n        boolean playAgain = true;\n        int highScore = 0;\n\n        System.out.println(\"\u6570\u5f53\u3066\u30b2\u30fc\u30e0\u3078\u3088\u3046\u3053\u305d\uff01\");\n\n        while (playAgain) {\n            int minRange = 1;\n            int maxRange = 100;\n            int randomNumber = (int) (Math.random() * (maxRange - minRange + 1)) + minRange;\n            int attempts = 0;\n\n            System.out.println(\"1\u304b\u3089100\u307e\u3067\u306e\u6570\u3092\u5f53\u3066\u3066\u304f\u3060\u3055\u3044\uff01\");\n\n            while (true) {\n                System.out.print(\"\u4e88\u60f3\u3057\u305f\u6570\u5b57\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044: \");\n                if (!scanner.hasNextInt()) {\n                    System.out.println(\"\u7121\u52b9\u306a\u5165\u529b\u3067\u3059\u3002\u6570\u5024\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002\");\n                    scanner.next(); \/\/ \u4e0d\u6b63\u306a\u5165\u529b\u3092\u30af\u30ea\u30a2\n                    continue;\n                }\n                int guessedNumber = scanner.nextInt();\n                attempts++;\n\n                if (guessedNumber &lt; randomNumber) {\n                    System.out.println(\"\u3082\u3063\u3068\u5927\u304d\u3044\u6570\u5b57\u3067\u3059\u3002\");\n                } else if (guessedNumber > randomNumber) {\n                    System.out.println(\"\u3082\u3063\u3068\u5c0f\u3055\u3044\u6570\u5b57\u3067\u3059\u3002\");\n                } else {\n                    System.out.println(\"\u304a\u3081\u3067\u3068\u3046\u3054\u3056\u3044\u307e\u3059\uff01\u6b63\u89e3\u3067\u3059\uff01\");\n                    System.out.println(\"\u3042\u306a\u305f\u306e\u8a66\u884c\u56de\u6570: \" + attempts);\n                    if (attempts &lt; highScore || highScore == 0) {\n                        highScore = attempts;\n                        System.out.println(\"\u65b0\u3057\u3044\u30cf\u30a4\u30b9\u30b3\u30a2\uff01\u8a66\u884c\u56de\u6570: \" + highScore);\n                    } else {\n                        System.out.println(\"\u30cf\u30a4\u30b9\u30b3\u30a2\u306f\" + highScore + \"\u56de\u3067\u3059\u3002\");\n                    }\n                    break;\n                }\n            }\n\n            System.out.print(\"\u3082\u3046\u4e00\u5ea6\u30d7\u30ec\u30a4\u3057\u307e\u3059\u304b\uff1f (y\/n): \");\n            String playChoice = scanner.next();\n            playAgain = playChoice.equalsIgnoreCase(\"y\");\n        }\n\n        System.out.println(\"\u30b2\u30fc\u30e0\u3092\u7d42\u4e86\u3057\u307e\u3059\u3002\");\n        System.out.println(\"\u6700\u7d42\u30cf\u30a4\u30b9\u30b3\u30a2: \" + highScore);\n        scanner.close();\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[76,4,94],"tags":[75,3],"class_list":["post-25335","post","type-post","status-publish","format-standard","hentry","category-java","category-programming","category-94","tag-java","tag-programming"],"aioseo_notices":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/25335","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=25335"}],"version-history":[{"count":1,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/25335\/revisions"}],"predecessor-version":[{"id":25336,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/25335\/revisions\/25336"}],"wp:attachment":[{"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=25335"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=25335"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=25335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}