[英]Compare value in for loop
我正在做2個隨機卡生成器。 我想知道哪個更高。 在以下示例中,如何將當前值與先前值進行比較?
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);
}
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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.