Question: Question about Java ArrayList. Question 10 Assume that the following code has been executed (same for Questions 7 thru 10): ArrayList plot = new ArrayList
Question about Java ArrayList.
Question 10
Assume that the following code has been executed (same for Questions 7 thru 10):
ArrayListplot = new ArrayList (); Point p = new Point( 12, 16 ); plot.add( p ); plot.add( new Point( 0, 0 ) ); plot.add( new Point( 4, 8 ) ); plot.add( 2, new Point( 5, 10 ) ); p = plot.get( 0 ); p = plot.remove( 1 ); plot.add( new Point( -5, 5 ) );
Which Point is returned by the following expression? plot.get( 5 )
| 5,10 |
| 4,8 |
| None -- the statement throws a runtime exception |
| The value null is returned |
| -5,5 |
Flag this Question
Question 11
Assume that the following code has been executed (same for Questions 11 thru 14):
ArrayListnums = new ArrayList (); nums.add( 12 ); nums.add( 32 ); nums.add( 15 ); nums.add( 2, 11 ); nums.add( 6 ); int s = nums.size() ; int sum = 0; Iterator it = nums.iterator(); while( it.hasNext() ) { int n = it.next(); if ( n % 2 == 1 ) sum = sum + n; } nums.remove( 0 );
What is the value of the variable 's'?
| 5 |
| 6 |
| 4 |
| 7 |
| 2 |
Flag this Question
Question 12
Assume that the following code has been executed (same for Questions 11 thru 14):
ArrayListnums = new ArrayList (); nums.add( 12 ); nums.add( 32 ); nums.add( 15 ); nums.add( 2, 11 ); nums.add( 6 ); int s = nums.size(); int sum = 0; Iterator it = nums.iterator(); while( it.hasNext() ) { int n = it.next(); if ( n % 2 == 1 ) sum = sum + n; } nums.remove( 0 );
What is the value of the variable 'sum'?
| 26 |
| 50 |
| 15 |
| 76 |
| 78 |
Flag this Question
Question 13
Assume that the following code has been executed (same for Questions 11 thru 14):
ArrayListnums = new ArrayList (); nums.add( 12 ); nums.add( 32 ); nums.add( 15 ); nums.add( 2, 11 ); nums.add( 6 ); int s = nums.size(); int sum = 0; Iterator it = nums.iterator(); while( it.hasNext() ) { int n = it.next(); if ( n % 2 == 1 ) sum = sum + n; } nums.remove( 0 );
How many elements remain on the list when the code is finished executing?
| 6 |
| 1 |
| 7 |
| 5 |
| 4 |
Flag this Question
Question 14
Assume that the following code has been executed (same for Questions 11 thru 14):
ArrayListnums = new ArrayList (); nums.add( 12 ); nums.add( 32 ); nums.add( 15 ); nums.add( 2, 11 ); nums.add( 6 ); int s = nums.size(); int sum = 0; Iterator it = nums.iterator(); while( it.hasNext() ) { int n = it.next(); if ( n % 2 == 1 ) sum = sum + n; } nums.remove( 0 );
What is the value of the first element remaining on the list?
| 32 |
| 11 |
| 12 |
| 6 |
| 15 |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
