Case: the array content is the same

Case: the array content is the same

//需求:设计一个方法,用于比较两个数组的内容是否相同
public class HelloWorld{
    
    
    public static void main(String[] args){
    
    
        int x[] = {
    
    23,43,23};
        int y[] = {
    
    23,43,23};
        boolean flag = compare(x,y);
        System.out.println(flag);
    }
    public static boolean compare(int x[],int y[]){
    
    
        if(x.length!=y.length){
    
    
            return false;
        }
        for(int a = 0; a<x.length; a++){
    
    
            if(x[a]!=y[a]){
    
    
                return false;
            }
        }
        return true;
    }
}

Guess you like

Origin blog.csdn.net/taoyingle/article/details/115262307
Recommended