2021-02-10 09:40:19 -05:00

45 lines
907 B
Java

/*
* 6 ints will be put into an ArrayList listInts
* copy only negative ints to a new ArrayList listNegInts
* Output the number of negative elements and the negatives list
*
* input: 5 -2 0 9 -66 -4
* output:
* 3
* -2
* -66
* -4
*/
import java.util.Scanner;
import java.util.ArrayList;
public class arrayListFun{
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
ArrayList<Integer> listInts = new ArrayList<>();
ArrayList<Integer> listNegInts = new ArrayList<>();
//take in array list listInts TODO
for (int i =0; i<6;i++){
listInts.add(scnr.nextInt());
}
//Find negative INTS and make a list
for (int i:listInts){
if (i<0){
listNegInts.add(i);
}
}
//Print out the neg list size and print out the contents
System.out.println(listNegInts.size());
for (int i:listNegInts){
System.out.println(i);
}
scnr.close();
}
}