Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

2d array

807600Nov 23 2007 — edited Nov 23 2007
my code is not working properly.

there is a 2d array and the args array. if any of the str[][] arrays match the command line arguments, it should return true, therefore java TwoDArray fgu should return true. but everytime i run this code the output is always false. does anyone know what i've done wrong?
class TwoDArray {

    public static void main(String[] args) {
	String[][] str = {
	    {"a","d"},
	    {"d","q","t","x"},
	    {"f","g","u"}
        };
	System.out.println(areIdentical(args,str));
    } 

    static boolean areIdentical(String args[], String str[][]) {
	for(int i = 0; i < str.length; i++) {
            int count = 0;
	    for(int j = 0; j < str.length; j++) {
if(str[i].length != args.length) break;
if(str[i][j] != args[j]) break;
else count++;

}
if(count == str[i].length) return true;
}
return false;
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 21 2007
Added on Nov 23 2007
17 comments
199 views