In: Computer Science
Write Java code that accepts the integer input (from keyboard) in an arraylist named num1 and stores the even integers of num1 in another arraylist named evennum.
CODE:
import java.util.*;
class Array_List{
public static void main(String[] args) {
Scanner scan=new
Scanner(System.in);
ArrayList<Integer> num1=new
ArrayList<Integer>();
ArrayList<Integer>
evennum=new ArrayList<Integer>();
int n,count=0;
System.out.print("Enter
num:");
n=scan.nextInt();
while(n>0)
{ count+=1;
num1.add(n);
System.out.print("Enter num:");
n=scan.nextInt();
}
for(Integer numb:num1)
{
if(numb%2==0)
{
evennum.add(numb);
}
}
System.out.println("evennum list
is:"+evennum);
}
}
OUTPUT:
If you have any doubts please COMMENT...
If you understand the answer please give THUMBS UP...