An Example of BitSet by NumSeries
From Java Example Source Code
Contents |
[edit] Overview - An Example of BitSet by NumSeries
This Java example program shows how to use BitSet.
[edit] Java Source Code
- Package: com.darwinsys
- File: NumSeries.java
package com.darwinsys;
import java.util.BitSet;
public class NumSeries {
public static void main(String[] args) {
for (int i = 1; i <= months.length; i++)
System.out.println("Month # " + i);
for (int i = 0; i < months.length; i++)
System.out.println("Month " + months[i]);
BitSet b = new BitSet();
b.set(0); // January
b.set(3); // April
for (int i = 0; i < months.length; i++) {
if (b.get(i))
System.out.println("Month " + months[i] + " requested");
}}/** The names of the months. See Dates/Times chapter for a better way */protected static String months[] =
{ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November",
"December" };
}
[edit] What Result You Can Get
Run the program, you will get:
Month # 1 Month # 2 Month # 3 Month # 4 Month # 5 Month # 6 Month # 7 Month # 8 Month # 9 Month # 10 Month # 11 Month # 12 Month January Month February Month March Month April Month May Month June Month July Month August Month September Month October Month November Month December Month January requested Month April requested
[edit] Required External Libraries and/or Files for this Java Example
Need nothing.
[edit] How to Run this Java Example Program
We recommend running this Java example program with Eclipse.
For assistance in working with Eclipse, please see How to Run Java Program with Eclipse.
It's fairly easy.
[edit] Question & Answer
Any question?
Click edit and post your question or answer here.
