Java-打破内部循环
我有一个2D数组,需要做一个for循环,遍历每一行,当整数停止连续增加时,找到索引+1。例如,如果第一行是{1,2,3,4,9,10,11,20},我的方法应该设置Java-打破内部循环,java,if-statement,Java,If Statement,我有一个2D数组,需要做一个for循环,遍历每一行,当整数停止连续增加时,找到索引+1。例如,如果第一行是{1,2,3,4,9,10,11,20},我的方法应该设置count1=4。break语句用于终止内部循环并继续执行外部循环的下一个序列 public static int[][] reshuffle(int[][] board) { int count1 =0; int count2 =0; int count3 =0; i
count1=4
。break语句用于终止内部循环并继续执行外部循环的下一个序列
public static int[][] reshuffle(int[][] board) {
int count1 =0;
int count2 =0;
int count3 =0;
int count4 =0;
for(int i=0;i<4;i++) {
for (int j = 0; j < 14; j++) {
if (i==0 && board[i][j] + 1 != board[0][j + 1]) {
count1 = j+1;
break;
} else if (i==1 && board[i][j] + 1 != board[1][j] + 1) {
count2 = j+1;
break;
} else if (i==2 && board[i][j] + 1 != board[2][j] + 1) {
count3 = j+1;
break;
} else if (i==3 && board[i][j] + 1 != board[3][j] + 1) {
count4 = j+1;
break;
}
}
}
}
public static int[][]重新洗牌(int[][]板){
int count1=0;
int count2=0;
int count3=0;
int count4=0;
对于(int i=0;i您可以使用标签并断开这些标签,但这是:
public static int[][]重新洗牌(int[][]板){
int count1=0;
int count2=0;
int count3=0;
int count4=0;
对于(int i=0;i您可以使用标签并断开这些标签,但这是:
public static int[][]重新洗牌(int[][]板){
int count1=0;
int count2=0;
int count3=0;
int count4=0;
对于(int i=0;i我认为您有一个逻辑错误,因为i=3
board[i][j]+1
将等于board[3][j]+1
,我认为您的意思是:
public static int[][] reshuffle(int[][] board) {
int count1 = 0;
int count2 = 0;
int count3 = 0;
int count4 = 0;
for(int i=0;i<4;i++) {
for (int j = 0; j < 14; j++) {
if (i==0 && board[i][j] + 1 != board[0][j + 1]) {
count1 = j+1;
break;
} else if (i==1 && board[i][j] + 1 != board[1][j + 1]) {
count2 = j+1;
break;
} else if (i==2 && board[i][j] + 1 != board[2][j + 1]) {
count3 = j+1;
break;
} else if (i==3 && board[i][j] + 1 != board[3][j + 1]) {
count4 = j+1;
break;
}
}
}
}
public static int[][]重新洗牌(int[][]板){
int count1=0;
int count2=0;
int count3=0;
int count4=0;
对于(int i=0;i我认为您有一个逻辑错误,因为i=3
board[i][j]+1
将等于board[3][j]+1
,我认为您的意思是:
public static int[][] reshuffle(int[][] board) {
int count1 = 0;
int count2 = 0;
int count3 = 0;
int count4 = 0;
for(int i=0;i<4;i++) {
for (int j = 0; j < 14; j++) {
if (i==0 && board[i][j] + 1 != board[0][j + 1]) {
count1 = j+1;
break;
} else if (i==1 && board[i][j] + 1 != board[1][j + 1]) {
count2 = j+1;
break;
} else if (i==2 && board[i][j] + 1 != board[2][j + 1]) {
count3 = j+1;
break;
} else if (i==3 && board[i][j] + 1 != board[3][j + 1]) {
count4 = j+1;
break;
}
}
}
}
public static int[][]重新洗牌(int[][]板){
int count1=0;
int count2=0;
int count3=0;
int count4=0;
for(int i=0;ibreak
仅退出内部循环-现在似乎是学习如何使用调试器的好时机。您能否提供int[]板< /代码>示例?<代码>破解< /Cord>语句可以从双<代码>中取出for循环<代码>。您需要考虑另一种方式。例如,您可以尝试在<代码>公共int GETCONTROFROW(INT[R]行)中放置第二个<代码> for循环<代码>。
methodbreak
仅退出内部循环-现在似乎是学习如何使用调试器的好时机。您能否提供int[]板< /代码>示例?<代码>破解< /Cord>语句可以从双<代码>中取出for循环<代码>。您需要考虑另一种方式。例如,您可以尝试在<代码>公共int GETCONTROFROW(INT[R]行)中放置第二个<代码> for循环<代码>。
method我认为标签应该在两个循环之外。我认为标签应该在两个循环之外。击败我…你是正确的。其他三个案例将始终失败。这解决了我的问题。击败我…你是正确的。其他三个案例将始终失败。这解决了我的问题。