Hello I want to write a loop that quit the loop if the user hits Enter or there is negative number. this is what i have so far. it only quits the loop if user enter characters.
import java.util.Scanner;
import java.util.ArrayList;
public class loop {
public static void main(String[] args) {
System.out.println("Enter a positive number: ");
Scanner sc = new Scanner(System.in);
ArrayList<Integer> list= new ArrayList<Integer>();
while (sc.hasNextInt()){
list.add(sc.nextInt());
sc=new Scanner(System.in);
thanks