blogspot.com-GA4

星期二, 8月 22, 2006

剪刀、石頭、布

import java.util.*;

public class FingerGame {
public static void main(String[] args){
String[] sa_finger = {"剪刀","石頭","布"};
Scanner scr = new Scanner(System.in);
String scomp = "",suser = "";

int icomputer = (int)(Math.random()*10%3 + 1);
scomp = String.valueOf(icomputer);

System.out.println("想猜拳嗎?\n請選擇你要出的拳:");
System.out.println("1.剪刀");
System.out.println("2.石頭");
System.out.println("3.布");

suser = scr.next();

if (!suser.equals("1")&&!suser.equals("2")&&!suser.equals("3")){
System.out.println("輸入不正確!!");
return;
}

System.out.println("你出" + sa_finger[Integer.parseInt(suser)-1]);
System.out.println("電腦出" + sa_finger[icomputer-1]);

if (suser.equals(scomp)){
System.out.println("平手!!");
}else if (suser.equals("1")&&scomp.equals("3")){
System.out.println("你贏了!!");
}else{
System.out.println("你輸了!!");
}
}
}

沒有留言: