Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 2019/12/28(土)
- // 性善説コード
- import java.util.*;
- public class Janken {
- public static void main(String[] args) {
- boolean isPlay = true;
- String youStr;
- int you;
- int cpu;
- Scanner scanner = new Scanner(System.in);
- Random random = new Random();
- System.out.println("ジャンケンをします");
- while (isPlay) {
- System.out.println("グーなら0、チョキなら1、パーなら2を入力して下さい");
- you = scanner.nextInt();
- if (you < 0 || you >2) {
- System.out.println("0、1、2のいずれかを入力して下さい\n");
- continue;
- }
- System.out.println("あなたの手は" + you + "です");
- cpu = random.nextInt(3); // cpuは0~2
- System.out.println("ジャンケン、ポン!\n");
- for (long i = 1; i <= 2_000_000_000L; i++) { ; }
- System.out.println("コンピュータの手は" + cpu + "です");
- if (you == cpu) {
- System.out.println("あいこです\n");
- } else if ((you + 1) % 3 == cpu) { // youとcpu = 0と1 1と2 2と0
- System.out.println("あなたの勝ちです!\n");
- isPlay = decide();
- } else {
- System.out.println("残念、あなたの負けです…\n");
- isPlay = decide();
- }
- }
- }
- public static boolean decide() {
- boolean isPlay;
- int res;
- Scanner scanner = new Scanner(System.in);
- while (true) {
- System.out.println("続けますか? Yesなら1、Noなら0を入力して下さい");
- res = scanner.nextInt();
- if (res == 1) {
- return true;
- } else if (res == 0) {
- return false;
- } else {
- System.out.println("0か1を入力して下さい\n");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement