7 つの数字のうち 5 つの最小数字を連続して出力したいが、重複した値を出力したくないので、このコードを書きました。今、いくつかの例外を与えています。
これをどうするか?
の動的タイプが必要だと思いますが、Arraylist
それを正確に適用することはできません。
class mycode{
public static void main(String[] args) {
boolean lowStraightFound = false;
int firstCard=0 ;
int firstCardIndex = 0;
int lastCard =0;
int lastCardIndex = 0;
int c[]={1,2,3,3,4,5,7};
int[] inarow = new int[20];
int index[]=new int[5];
int last=0;
int num = c.length;
for (int i = 0; i < num; i++) {
int card = c[i];
if (lastCard!= 0) {
int lastOrd = lastCard;
int cardOrd = card;
if (cardOrd - lastOrd == 1) {
inarow[0]++;
lastCardIndex = i;
last++;
index[last]=i;
} else if (cardOrd - lastOrd != 0) {
inarow[0] = 1;
firstCard = card;
firstCardIndex = i;
last=0;
index[last]=i;
}else if(cardOrd - lastOrd == 0){
index[last]=i;
last=i;
}
} else {
firstCard = card;
firstCardIndex = i;
index[last]=i;
}
lastCard = card;
if (inarow[0] == 5) {
lowStraightFound = true;
break;
}
}
for (int i = last; i >= 0; i--) {
System.out.println(c[i]);
}
}
}