如何通过将它们作为参数传递给方法来比较Java中的两个字符串数组

时间:2017-04-18 20:01:59

标签: java arrays

我试图将两个String数组作为参数传递给Java中的方法,然后比较它们以检查它们是否部分相等。

但我收到编译时错误。

CE:  error: ';' expected
   String check(String s1[],String s2[]){
}

1 个答案:

答案 0 :(得分:0)

<强>提示 它接了一个家庭作业问题,所以我会给你一个提示:

public class Test {

    public static void main(String args[]) {
        //define your arrays
        String array1[] = {"Hello", "Java"};
        String array2[] = {"Hello", "World"};

        //call your method which make the comparison 
        boolean check = check(array1, array2);
        System.out.println(check ? "Equal" : "Not equal");
    }

    //Your method must return a boolean, true for equal or false
    private static boolean check(String s1[], String s2[]) {
        //make your condition here
        boolean b = //(your action must return a true or false)..
        return b;
    }
}