- class Test
- {
- static boolean isEquals(int[] a, int[] b)
- {
- boolean bl=false;
- //定义一个boolean型变量,用于存储判断得到的值;
- if (a.length != b.length)
- {
- bl= false;
- }else
- {
- for (int i = 0; i < a.length; i++)
- {
- if(a[i]!=b[i])
- {
- bl=false;
- break;
- //如果有一组数据不同时,运行break,循环结束;
- }else
- {
- bl=true;
- }
- }
- }
- return bl;
- }
- public static void main(String[] args)
- {
- int a[]={1,4,2};
- int b[]={2,3,2};
- int c[]={1,4,2};
- System.out.println(isEquals(a,b));
- System.out.println(isEquals(a,c));
- }
- }
复制代码 |