Please help fix my code.
This is the question and code
Given the IntNode class, define the findMax() method in the CustomLinkedList class that returns the largest value in the list or returns -99 if the list is empty. Assume all values in the list are non-negative.
Ex: If the list contains:
head -> 14 -> 191 -> 186 -> 181
findMax(headObj) returns 191.
Ex: If the list contains:
head ->
findMax(headObj) returns -99.
CustomLinkedList.java
public class CustomLinkedList {
public static int findMax(IntNode headObj) {
IntNode temp = headObj;
int ans = -99;
while(temp.getNext() != null){
if(temp.getNodeData() >
ans){
ans =
temp.getNodeData();
}
temp = temp.getNext();
}
// return the ans.
return ans;
}
public static void main(String[] args) {
IntNode headObj;
IntNode currObj;
IntNode lastObj;
int i;
boolean result;
// Create head node
headObj = new IntNode(-1);
lastObj = headObj;
// Add nodes to the list
for (i = 0; i < 20; ++i) {
currObj = new IntNode(i);
lastObj.insertAfter(currObj);
lastObj = currObj;
}
max = findMax(headObj);
System.out.println(max);
}
}
I have two errors which are: