Consider the following code snippet: ArrayList<Integer> num1 = new ArrayList<Integer>() ;
Int data;
Scanner in = new Scanner(System.in) ;
For (int i = 0; i < 5; i++)
{
Data = in.nextInt() ;
Num1.add(data) ;
If (data == 0 && num1.size() > 3)
{
Num1.remove(num1.size() - 1) ;
}
}
System.out.println("size is : " + num1.size() ) ;
What is the output of the given code snippet if the user enters 1,2,0,0,1 as the input?
A) size is : 1
B) size is : 2
C) size is : 4
D) size is : 0
Correct Answer:
Verified
Q67: Which one of the following is a
Q68: Consider the following code snippet:
Int[][] arr =
{
{
Q70: What is the value of the cnt
Q71: Consider the following line of code for
Q72: What is the output of the following
Q73: Consider the following code snippet: ArrayList<Double> somedata
Q74: What is the value of myArray[1][2] after
Q90: Which one of the following statements about
Q91: What is the result of the following
Q96: Your program needs to store an integer
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