我需要将10个整数读入ArrayList,然后将它们编程为两组:“Positive Integers”和“Negative Integers”.
我有两个ArrayLists和一个if语句来确定每个整数应该去哪里,但是我不知道使用什么变量来使这个工作.这是我到目前为止:
import java.util.*;
public class Sort {
public static void main (String [] args) {
ArrayList pos = new ArrayList();
ArrayList neg = new ArrayList();
Scanner sc = new Scanner(System.in);
int i=0 ;
while(i <= 10) {
System.out.println("enter an integer");
if(??? < 0) { //here is where my question is
neg.add(sc.nextInt());
} else {
pos.add(sc.nextInt());
}
i++;
}
System.out.println("positive numbers" + pos);
System.out.println("negative numbers" + neg);
}
}