1. What does the following code print? ArrayList<Integer> q7 = new ArrayList<Int
ID: 3721639 • Letter: 1
Question
1. What does the following code print?
ArrayList<Integer> q7 = new ArrayList<Integer>();
q7.add(3);
q7.add(9);
q7.add(4);
q7.add(6);
for (int i=0; i<q7.size(); i+=1) {
q7.remove(i);
q7.add(i);
}
System.out.println(q7);
2. What does the following code print?
double [ ] array = {1.3, 4.8, 9.7};
ArrayList<Double> list = new ArrayList<Double>();
for (double v : array) {
list.add(0,v);
}
System.out.println(list);
3. What does the following method do?
public static int [ ] q6( int [ ] p ) {
int [ ] n = new int [ p.length ];
n = p;
return n;
Explanation / Answer
1) [9, 6, 1, 3] 2) [9.7, 4.8, 1.3] 3) This method directly returns the argument that was passed to the method
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.