Which one of the following code snippets accepts the integer input in an array named num1 and stores the odd integers of num1 in another array named oddnum?
A) ArrayList<Integer> num1 = new ArrayList<Integer>() ;
ArrayList<Integer> oddnum = new ArrayList<Integer>() ;
Int data;
Scanner in = new Scanner(System.in) ;
For (int i = 0; i < 10; i++)
{
Data = in.nextInt() ;
Num1.add(data) ;
If (num1.get(i) % 2 == 0)
{
Oddnum.add(num1.get(i) ) ;
}
}
B) ArrayList<Integer> num1 = new ArrayList<Integer>() ;
ArrayList<Integer> oddnum = new ArrayList<Integer>() ;
Int data;
Scanner in = new Scanner(System.in) ;
For (int i = 0; i < 10; i++)
{
Data = in.nextInt() ;
Num1.add(data) ;
If (num1.get(i) % 2 != 0)
{
Oddnum.add(num1.get(i) ) ;
}
}
C) ArrayList<Integer> num1 = new ArrayList<Integer>() ;
ArrayList<Integer> oddnum = new ArrayList<Integer>() ;
Int data;
Scanner in = new Scanner(System.in) ;
For (int i = 0; i < 10; i++)
{
Data = in.nextInt() ;
Num1.add(data) ;
If (num1.get(i) % 2 == 0)
{
Oddnum.add(num1[i]) ;
}
}
D) ArrayList<Integer> num1;
ArrayList<Integer> oddnum = new ArrayList<Integer>() ;
Int data;
Scanner in = new Scanner(System.in) ;
For (int i = 0; i < 10; i++)
{
Data = in.nextInt() ;
Num1.add(data) ;
If (num1[i] % 2 != 0)
{
Oddnum.add(num1[i]) ;
}
}
Correct Answer:
Verified
Q2: Consider the following line of code:
Int[] somearray
Q17: Which code snippet prints out the elements
Q22: The following statement gets an element from
Q23: When an array reading and storing input
Q23: The binary search is faster than the
Q26: Which statements are true regarding the differences
Q32: It may be necessary to "grow" an
Q35: Which code snippet finds the largest value
Q37: What is the value of the count
Q51: Suppose you wish to use an array
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents