heres my code:
import java.util.Scanner;
import java.lang.Integer;
public class hmwrk4
{
public static void main(String [] args)
{Scanner kbInput = new Scanner(System.in);
System.out.print("number of the element to delete: ");
int numEle = kbInput.nextInt();
Node n8 = new Node(new Integer(8), null);
Node n7 = new Node(new Integer(7), n8);
Node n6 = new Node(new Integer(6), n7);
Node n5 = new Node(new Integer(5), n6);
Node n4 = new Node(new Integer(4), n5);
Node n3 = new Node(new Integer(3), n4);
Node n2 = new Node(new Integer(2), n3);
Node n1 = new Node(new Integer(1), n2);
Node n0 = new Node(new Integer(0), n1);
Node head = new Node(new Integer(0), n0);
Node prev = new Node(null);
Node curr = new Node(new Integer(0),n0);
if(numEle > 8 || numEle < 0)
{System.out.println("error: out of bounds");
System.exit(0);
}
else if(numEle == 0)
{head = head.getNext();
}
else
{
while(curr != null && numEle > curr.getItem())
{prev = curr;
curr = curr.getNext();
}
if(curr.getNext() == null)
prev.setNext(null);
else
prev.setNext(curr.getNext());// = curr.getNext();
}
System.out.println("result: ");
curr = head.getNext();
System.out.print(curr.getItem() + " ");
while(curr.getNext() != null)
{curr = curr.getNext();
System.out.print(curr.getItem() + " ");
}
} // end of main
//end of class
}
class Node{
private Object item;
private Node next;
public Node(Object newItem){
item = newItem;
next = null;
}
public Node(Object newItem, Node nextNode){
item = newItem;
next = null;
}
public void setItem(Object newItem){
item = newItem;
}
public Object getItem(){
return item;
}
public void setNext(Node nextNode){
next = nextNode;
}
public Node getNext(){
return next;
}
}//end of class
The assignment: to delete a user input number of a linked list and printing the result.
My problem:
Error
hmwrk4.java:34: operator > cannot be applied to int,java.lang.Object
while(curr != null && numEle > curr.getItem())