剪刀石頭布流程圖.GIF 

import java.util.*;
public class Chaotic {
    public static void main(String[] args) {
        Scanner scanner= new Scanner(System.in);
        int x = (int)(Math.random()*3);
        System.out.println("請猜拳...剪刀:0、石頭:1、布:2");
        int y = scanner.nextInt();
        System.out.println("您出:" + y + "  ~  " + "電腦出:" + x);
        int cp = (x-y+3)%3;//Computation計算
        if(cp == 0){
            System.out.println("平手喔!");
        }else if(cp == 1){
            System.out.println("電腦win");
        }else{
            System.out.println("you win");
        }
    }
}

創作者介紹
創作者 pandaalbert(冠文)的部落格 的頭像
pandaalbert冠文

pandaalbert(冠文)的部落格

pandaalbert冠文 發表在 痞客邦 留言(0) 人氣( 328 )