My method is not working for some reason, even though i have done in exactly the same way the books showed.
Could you please take a look at it and let me know what went wrong?
Thank you
P.S. I tried to use DEBUG technique and it seems that the method doesn't even go through the list.

public static IntNode listSearch(IntNode head, int target) {

        IntNode cur;

        for (cur = head; cur != null; cur = cur.link) 
            if (target == cur.data){
                System.out.println("DEBUG" + cur.data);
            }
            else
              System.out.println("DEBUG" + null); 
        return null;

}

this is how i call my method in main my.listSearch(null, 21); // method does not work

My method is not working for some reason, even though i have done in exactly the same way the books showed.
Could you please take a look at it and let me know what went wrong?
Thank you
P.S. I tried to use DEBUG technique and it seems that the method doesn't even go through the list.

public static IntNode listSearch(IntNode head, int target) {

        IntNode cur;

        for (cur = head; cur != null; cur = cur.link) 
            if (target == cur.data){
                System.out.println("DEBUG" + cur.data);
            }
            else
              System.out.println("DEBUG" + null); 
        return null;

}

this is how i call my method in main my.listSearch(null, 21); // method does not work

As per my knowledge, I think you should not check objects against null.... Problem with for loop..

As per my knowledge, I think you should not check objects against null.... Problem with for loop..

You are right!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.