Menu
Topics Index
...
`

BitSet2898


If you need explanation Read this topic

If you need Answer Take test on this topic

BitSet2898
What will be the output of the following program?
import java.util.*;
public class BitsAre {
    public static void main(String[] args) {
        BitSet bs = new BitSet();
        for (String s : new String[]{"LeaRn", "PracTice", "coMpetE"}) {
            for (int i = 0; i < s.length(); i++) {
                if (Character.isLowerCase(s.charAt(i)))
                    bs.set(i);
            }
        }
        System.out.println(bs);
    }
}

A. {1, 2, 4}
B. {1, 2, 3, 4, 5, 6, 7}
C. {0, 1, 2, 3, 4, 5, 6, 7}
D. Some other output
E. Compilation Error or Runtime Error
Topic: Java BitSet

If you need explanation Read this topic

If you need Answer Take test on this topic

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

Answer is C .Bitset tries to set the bit at the particular index whenever value at that index location is of lower case.Finally when we try to print the object,decimal representation of that index is displayed with the indices printed from lowest to highest order

Posted by Shashanka Mogaliraju    2014-08-26 08:42:43


Ans is C.

Posted by Gopinath Manchikanti    2014-08-26 08:45:00


Answer is C .Bitset tries to set the bit at the particular index whenever value at that index location is of lower case.Finally when we try to print the object,decimal representation of that index is displayed with the indices printed from lowest to highest order

Posted by Asma Mujtaba Khan    2014-08-26 09:14:50


c

Posted by Rayapudi Ramya    2014-08-26 14:31:33


D ,, for every string i starts from 0

Posted by Raju VarshnEy    2014-08-26 14:36:04


Congratulations Shashanka Mogaliraju. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-08-27 04:41:18


© meritcampus 2019

All Rights Reserved.

Open In App