Can you please tell the error in the code

import java.util.*;

class node

{

int n;

node next;

node(int num)
{

n=num;

next=null;
}
}

class list

{

node first;

node temp;

int n;

list()

{

first=null;

temp=null;

}

void insert(int n1)

{

node n=new node(n1);

if(first==null)

{

first=n;

first.next=null;

temp=first;

}

else

{

temp.next=n;

temp=n;

temp.next=null;

}

}

void print()

{
node t=first;

while(t.next!=null)

{

System.out.println(t.n);

t=t.next;

}

}

}

class Main

{

public static void main(String arr[])throws Exception

{

Scanner sc=new Scanner(System.in);

int temp=sc.nextInt();

int i,j;

list l=new list();

while(temp!=42)

{

l.insert(temp);

temp=sc.nextInt();

}

l.print();

}

}

The problem is in your print() method:
while(t.next!=null) should be

while(t != null)

On another note, the way you’re writing your code will drive anyone mad trying to read it. Try writing it something like this:

import java.util.*;

class Main{
public static void main(String arr[])throws Exception{

	Scanner sc=new Scanner(System.in);
	int temp = sc.nextInt();
	int i,j;
	List l = new List();

	while(temp != 42){
		l.insert(temp);
		temp=sc.nextInt();
	}
	l.print();
}//end main

}//END Main class

class Node{

int n;
Node next;

Node(int num){
	n=num;
	next=null; 
}//end constructor

}//END Node class

class List{

Node first;
Node temp;
int n;

List(){
	first=null;
	temp=null;
}//end constructor

void insert(int n1){
	Node n = new Node(n1);
	
	if(first==null){
		first=n;
		first.next=null;
		temp=first;
	}
	else{
		temp.next=n;
		temp=n;
		temp.next=null;
	}
}//end insert()

void print(){ 
	Node t = first;

	while(t != null){
		System.out.println(t.n);
		t = t.next;
	}
}//end print()

}//END List class

thank you