Created
October 28, 2012 08:04
-
-
Save KazumasaSUGAYA/3968018 to your computer and use it in GitHub Desktop.
CardGame
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
【引用先】 | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.Random; | |
public class CardGame { | |
/** | |
* @param args | |
* @throws IOException | |
*/ | |
public static void main(String[] args) throws IOException { | |
int i, ran1, ran2, cmp; | |
int taro_point = 0, hanako_point = 0; | |
//動物の種類は cat, dog, fish, lion, tigerの5種類 | |
String card[] = { "cat", "dog", "fish", "tiger" }; | |
String taro_card, hanako_card; | |
Random rnd = new Random(); | |
System.out.println("INPUT -- 何ターンの勝負を行いますか? : 1000以下"); | |
InputStreamReader reader = new InputStreamReader(System.in); | |
BufferedReader br = new BufferedReader(reader); | |
int n = Integer.parseInt(br.readLine()); | |
if (n < 1000) { | |
for (i = 0; i < n; i++) { | |
ran1 = rnd.nextInt(3) + 1; | |
ran2 = rnd.nextInt(3) + 1; | |
taro_card = card[ran1]; | |
hanako_card = card[ran2]; | |
cmp = taro_card.compareTo(hanako_card); | |
if (cmp > 0) { | |
taro_point += 3; | |
} else if (cmp == 0) { | |
taro_point += 1; | |
hanako_point += 1; | |
} else { | |
hanako_point += 3; | |
} | |
} | |
System.out.println("---OUTPUT---"); | |
System.out.println("太郎の得点 : " + taro_point); | |
System.out.println("花子の得点 : " + hanako_point); | |
} else { | |
System.out.println("NG"); | |
} | |
} | |
} | |
辞書順とはどういうことか?
文字コード表、アスキー表。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
compareToで比較してるけど、大文字と小文字だとどっちが大きい?