使用锯齿状数组确定上三角或下三角
Using jagged array to determine upper or lower triangular
我正在尝试使用锯齿状数组来确定矩阵是上三角形还是下三角形。
这是我的。
问题是方法returns对上三角和下三角都是正确的。
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
public static boolean isUpper(int[][] array){
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
if(array.length == array[i].length){
return true;
}
}
}
System.out.println("false");
return false;
}
public static void main(String args[]) {
int myA[][] = {{3,4,5},{6,7},{8}};
int myB[][] = {{8},{6,7},{5,4,3}};
isUpper(myB);
}
}
当任何内部数组的“长度”与包含数组的“长度”相同时,代码 return 为真。两个数组(`myA` 和 `myB`)的长度都是 `3`,这意味着如果任何内部数组的长度为 `3`,它将`return true`。 `myA` 和 `myB` 都有一个长度为 3 的内部数组(`{3,4,5}` 用于 `myA` 和 `{5,4,3}` 用于 `myB`)所以两者都将 return `true`.
检查第一行的长度应该return myA 为真,myB 为假
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Jagged {
public static boolean isUpper(int[][] array){
for (int i = 0; i < array.length; i++) {
if(array.length == array[0].length){
System.out.println("yes");
return true;
}
}
System.out.println("no");
return false;
}
public static void main(String args[]) {
int myA[][] = {{3,4,5},{6,7},{8}};
int myB[][] = {{8},{6,7},{5,4,3}};
isUpper(myA);
}
}
我正在尝试使用锯齿状数组来确定矩阵是上三角形还是下三角形。
这是我的。
问题是方法returns对上三角和下三角都是正确的。
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
public static boolean isUpper(int[][] array){
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
if(array.length == array[i].length){
return true;
}
}
}
System.out.println("false");
return false;
}
public static void main(String args[]) {
int myA[][] = {{3,4,5},{6,7},{8}};
int myB[][] = {{8},{6,7},{5,4,3}};
isUpper(myB);
}
}
当任何内部数组的“长度”与包含数组的“长度”相同时,代码 return 为真。两个数组(`myA` 和 `myB`)的长度都是 `3`,这意味着如果任何内部数组的长度为 `3`,它将`return true`。 `myA` 和 `myB` 都有一个长度为 3 的内部数组(`{3,4,5}` 用于 `myA` 和 `{5,4,3}` 用于 `myB`)所以两者都将 return `true`.
检查第一行的长度应该return myA 为真,myB 为假
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Jagged {
public static boolean isUpper(int[][] array){
for (int i = 0; i < array.length; i++) {
if(array.length == array[0].length){
System.out.println("yes");
return true;
}
}
System.out.println("no");
return false;
}
public static void main(String args[]) {
int myA[][] = {{3,4,5},{6,7},{8}};
int myB[][] = {{8},{6,7},{5,4,3}};
isUpper(myA);
}
}