Menu
Topics Index
...
`

BitSet


If you need explanation Read this topic

If you need Answer Take test on this topic

BitSet
What will be the output of the following program?
import java.util.BitSet;

public class LearnPracticeCompete {

    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);
                else
                    bs.flip(i);
            }
        }
        System.out.println(bs);
    }
}

A. {1, 2, 3, 4, 5, 6, 7}
B. {2, 6}
C. {0, 1, 2, 3, 4}
D. {0, 1, 3, 4, 5, 7}
E. Some other output
F. 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.

Ans is D. initially for the string LeaRn, bs will contain true values at indexes 1,2,4 because at indexes 0 and 3 uppercase is present. For the next String, index 0 will be inverted because of uppercase letter.. and indexes 1,2,3,4,6,7 will be set. For the last string indexes 2 and 6 will be unset as an upper case is present and the remaining is present

Posted by Nikhil Sulibhavi    2014-05-21 12:49:43


ans d.in 1st string if condition true for 1,2,4th bit remaining unset,2nd string 1,2,3,5,6,7 th bits are set true 0 and 4 th index bits unset,last string 0,1,3,4,5th bits true 2 and 6 th bit flipd

Posted by Maheshwari Natarajan    2014-05-21 13:18:57


Answer  :  D
> Initailly the bs will contain { 0,1,2,3,4}
> After running the String PracTice bs will contain { 1,2,3,5,6,7}
> and finally after running thString  comPetE bs will contain { 0,1,3,4,5,7} which are set beoz of the lower case alphabets present at these locations

Posted by Deepak Kumar Yadav    2014-05-21 13:20:29


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

Posted by Merit Campus    2014-05-22 05:11:17


© meritcampus 2019

All Rights Reserved.

Open In App