2016-04-10 18 views
0

私は2つのランダムなカードジェネレータをやっています。私はどちらが高いか知りたい。次の例で、現在の値と前の値を比較するにはどうすればよいですか?右のことですforループの値を比較してください

for (int i = 0; i < 2; i++){ 
    String suit = suits[deck[i]/13]; 
    String rank = ranks[deck[i] % 13]; 
    System.out.println("You have the " + rank + " of " + suit);     
} 
+0

あなたはスーツとランクの間で比較し、それらの高いをしたいです? – PacMan

+0

前の値を変数に格納してから2番目の値と比較するのはなぜですか? – Atri

答えて

0
String previousValue = null; 
for(...) { 
    String currentValue = ...; 

    // you can now compare previous with current, watch out for unset (null) 
    if(previousValue != null && currentValue (?) previousValue) {...} 

    //... any further processing 

    // following is the last line in your loop, so it is set for next loop iteration 
    previousValue = currentValue; 
} 
関連する問題