Reputation: 1206
The following code:
public static void print(ListNode p)
{
System.out.print("[");
if(p==null);
{
System.out.println("]");
return;
}
ListNode k = p.getNext();
//more code
}
causes the following compile error:
----jGRASP exec: javac -g Josephus_5_Rajolu.java
Josephus_5_Rajolu.java:53: error: unreachable statement
ListNode k = p.getNext();
^
1 error
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
Why is that happening? I am only returning if p = null. I want to do my other code if p!=null. Why is it unreachable?
Upvotes: 1
Views: 2044
Reputation: 388
Where are you instantiating ListNode K?
It looks like to me that the issue is ListNode k is not being instantiated.
I think you need something like this. ListNode k = new ListNode();
Are you creating this within your class?
Also you have a ; after if(p==null); That needs to be removed.
Upvotes: 1