package exercise_7;
public class Exercise7_10 {
public static void main(String[] args) {
int[][] test = new int[3][3];
for (int i = 0; i < test.length; i++) {
for (int j = 0; j < test[i].length; j++) {
int t = (int) (Math.random() * 2);
test[i][j]=t;
System.out.print(test[i][j]+ " ");
}
System.out.println();
}//自動生成一個3—3的數組
boolean flag=true;
for (int i = 0; i < test.length; i++) {
flag=true;
for (int j = 0; j < test[i].length-1; j++) {//判斷相同行
if (test[i][j]!=test[i][j+1]) {
flag=false;
if (flag) {
System.out.println("All is on row "+i);
break;
}
}
}
for (int j = 0; j < test[i].length-1; j++) {//判斷相同列
if (test[j][i]!=test[j+1][i]) {
flag=false;
if (flag) {
System.out.println("All is on column "+j);
break;
}
}
}
}
}
}
package exercise_7;
public class Exercise7_10 {
public static void main(String[] args) {
int[][] test = new int[3][3];
for (int i = 0; i < test.length; i++) {
for (int j = 0; j < test[i].length; j++) {
int t = (int) (Math.random() * 2);
test[i][j] = t;
System.out.print(test[i][j] + " ");
}
System.out.println();
}// 自動生成一個3—3的數組
boolean flag = true;
for (int i = 0; i < test.length; i++) {
flag = true;
for (int j = 0; j < test[i].length - 1; j++) {// 判斷相同行
if (test[i][j] != test[i][j + 1]) {
flag = false;
}
if (flag) {
System.out.println("All is on row " + i);
break;
}
}
for (int j = 0; j < test[i].length - 1; j++) {// 判斷相同列
if (test[j][i] != test[j + 1][i]) {
flag = false;
}
if (flag) {
System.out.println("All is on column " + j);
break;
}
}
}
}
}