For this Question: A number (n) is represented in Linked List such that each digit corresponds to a node in linked list. Add 1 to it.

<b>Note:-</b> Linked list representation of a number is from left to right i.e if the number is 123 than in linked list it is represented as 3->2->1<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>addOne()</b> that takes head node of the linked list as parameter.

Constraints:
1 <=length of n<= 1000Return the head of the modified linked list.Input 1:
456

Output 1:
457

Input 2:
999

Output 2:
1000, I have written this Solution Code:  
    static Node addOne(Node head)  
{  
    Node res = head;  
    Node temp = null, prev = null;  
  
    int carry = 1, sum;  
  
    while (head != null) //while both lists exist  
    {  
        sum = carry + head.data;  
  
        carry = (sum >= 10)? 1 : 0;  
  
        sum = sum % 10;  
  
        head.data = sum;  
  
        temp = head;  
        head = head.next;  
    }  
  if (carry > 0)  {
        Node x=new Node(carry);
        temp.next=x;} 
   
    return res;  
}  , In this Programming Language: Java, Now tell me if this Code is compilable or not?