For this Question: Given a singly linked list, find out the middle node of the linked list. For example, if given linked list is 1- >2- >3- >4- >5 then middle of the linked list is 3.

If there are even nodes, then there would be two middle nodes, then print both the middle elements. For example, if given linked list is 1- >2- >3- >4- >5- >6 then middle elements are 3 and 4.

In case of a single node print the value of only node.<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>findMiddleElement()</b> that takes head node of the linked list as parameter.

Constraints:
1 <=N<= 1000
1 <=value<= 1000find out middle node of the linked list.Sample Input 1:
5
1 2 3 4 5

Sample Output:
3



Sample Input 2:
6
1 2 3 4 5 6

Sample Output:-
3 4, I have written this Solution Code: public static void MiddleElement(Node head) {
    if(head==null){
       //System.out.println("khali");
       return;
    }
    int cnt=0;
    Node temp=head;
    while(temp!=null){
    cnt++;
    temp=temp.next;
    }
    if(cnt==1){
    System.out.println(head.val);
    return;
    }
    if(cnt==2){
    System.out.print(head.val);
    System.out.print(" ");
    System.out.println(head.next.val);
    return;
    }
    if(cnt%2!=0){
        temp=head;
        int cnt1=cnt/2;
        while (temp!=null) {
             if(cnt1==0){
                System.out.println(temp.val);
                return;
             }
             cnt1--;
             temp=temp.next;  
        }
        return;
    }
    temp=head;
        int cnt1=cnt/2-1;
        while (temp!=null) {
             if(cnt1==0){
                System.out.print(temp.val);
                System.out.print(" ");
                System.out.println(temp.next.val);
                return;
             }
             cnt1--;
             temp=temp.next;  
        }
    
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?