有 二 flip()方法的变体。本文对所有这些问题的描述如下:
null
1.翻转(int值): 此方法删除参数中指定的值。
public void flip(int value) Parameters : value : the value to flip. Return ValueThis method does not return a value.
// Java code to demonstrate the // working of flip(int value) in Bitset import java.util.*; public class Flip1 { public static void main(String[] args) { // declaring bitset BitSet bset = new BitSet( 6 ); // assigning values to bset bset.set( 0 ); bset.set( 1 ); bset.set( 2 ); bset.set( 3 ); // printing the original set System.out.println( "The original bitset is : " + bset); // using flip() to remove 2 bset.flip( 2 ); // printing final bitset // 2 is removed System.out.println( "The flipped bitset is : " + bset); } } |
输出:
The original bitset is : {0, 1, 2, 3} The flipped bitset is : {0, 1, 3}
2.翻转(int fromnum,int tonum): 此方法将从指定的fromnum(包含)到指定的tonum(排除)的每个位设置为其当前值的补码,即 将fromnum值删除为tonum-1值 .
public void flip(int fromnum,int tonum) Parameters : fromnum : start number to begin flipping. tonum : last-1 number to end flipping. Return Value : This method does not return a value.
// Java code to demonstrate the // working of flip(int fromnum, int tonum) in Bitset import java.util.*; public class Flip2 { public static void main(String[] args) { // declaring bitset BitSet bset = new BitSet( 6 ); // assigning values to bset bset.set( 0 ); bset.set( 1 ); bset.set( 2 ); bset.set( 3 ); // printing the original set System.out.println( "The original bitset is : " + bset); // using flip(fromnum,tonum) to remove 1 and 2 bset.flip( 1 , 3 ); // printing final bitset // 1 and 2 are removed System.out.println( "The flipped bitset is : " + bset); } } |
输出:
The original bitset is : {0, 1, 2, 3} The flipped bitset is : {0, 3}
本文由 阿斯塔·蒂亚吉 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 贡献极客。组织 或者把你的文章寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。 如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END