Simple input - error in code

cannot understand the technique,

please spot the error in my code

public static void main(String[] args) {
	// TODO Auto-generated method stub
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int sum = 0;
	while(true)
	{			
		sum = sum + n;
		if(sum > 0){
			System.out.println(n);
		}
		else{
			break;
		}
		n = sc.nextInt();
	}
	sc.close();
}

}

hi @shatarupa2509_6702bcc43c339df9 refer
public static void takeInput(){

    Scanner scn = new Scanner(System.in);
    int sum = 0;

    while(sum >= 0){

        int n = scn.nextInt();
        sum += n;

        if(sum < 0) break;
        System.out.println(n);
    }
}