info@meritcampus.com    +91-85006-22255
...
`

Vector test
What will be the output of the following program?
`import java.util.*;public class Hp00001 {    public static void main(String[] args) {        Vector vect = new Vector();        vect.add("1");    vect.add("2");        vect.add("3");    vect.add("4");        vect.add("5");    vect.add("6");        vect.add("7");    vect.add("8");        vect.add("9");    vect.add("10");        vect.add("11");        Object[] obj = new Object[11];        vect.copyInto(obj);        Arrays.sort(obj);        Collections.reverse(vect);        for (int index = 0; index < 11; index++)            if (vect.get(index) != obj[index])                System.out.print(vect.get(index) + " ");    }}`

 A. 1 2 3 4 6 7 8 9 10 11 B. 1 2 3 4 6 7 8 9 11 C. 11 10 9 8 7 6 4 3 2 1 D. 11 9 8 7 6 4 3 2 1 E. Compilation Error or Runtime Error
Topic:

### User comments below.All of them might not be correct.

option d is ans because the numbers are copied into obj and sorted and vect numbers are reversed then at 10 and 5 they become equal.. so they are not printed

Posted by Sai Lalitha Renduchintala    2013-05-07 12:36:54

c

Posted by Yeshu Yeshwanthi    2013-05-07 12:39:01

none of the given options is right..the sequence should be 11 10 9 8 7 5 4 3 2 1

Posted by Soumya Tata    2013-05-07 12:46:51

The answer is option D :: initially the vect numbers are copied into "obj" then the numbers are sorted as 1,2,3,4,5,6,7,8,9,10,11 then are reversed now..as..11,10,9,8,7,6,5,4,3,2,1 then at this point 10 and 5 bcome equal..!! thus the if condition is not satified hence 10 and 5 are not printed...thus it prints the rest of all vect numbers..i.e 11,9,8,7,6,4,3,2,1 ! hence the output will be D accordingly !! :)

Posted by Anchal Shetty    2013-05-07 12:51:59

ans is d as values in obj are of string type..sort array contains 1,10,11,2,3,4... wen dey r compared at index 1 dey'll bcom equal

Posted by Teja Potlapally    2013-05-07 12:55:11

option is d bcoz here sort function on strings sorts the values to 1 10 11 2 3 4 5 6 7 8 9...here as the sorting occurs on string function ,the values 10 and 11 comes bfore other values as the ascii value of 1 is less tahn ascii of 2 n so on...other than dat the values at the end are 1 10 11 2 3 4 5 6 7 8 9 in obj n 1 2 3 4 5 6 7 8 9 in vect.. here der is a match at 5 and 10 ..xcept dose values are printed..so output is 11 9 8 7 6 4 3 2 1

Posted by Pramod Jain    2013-05-07 13:04:23

Congratulations Sai Lalitha. You are today's daily dose winner. Can you please send us the mobile details and we will process the recharge tomorrow after considering the new likes.

Posted by Merit Campus    2013-05-07 15:40:13

ty mc received recharge...

Posted by Sai Lalitha Renduchintala    2013-05-11 06:06:14