Basically for user input 2, it will return:
00
01
10
11
if 4:
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
and so on for any given length k. I have to write the algorithm myself so I can't use any of java's libraries that deal with binary or bits. By thought process of how to go about this is as follow I just don't know how to implement it.
- Get the size of the user input and store it as k
- Create variable of length k that consists of all zero's
- Perform binary addition of +1 over and over until a string of all 1's is achieved
the stub to the class we were given is this:
public static ArrayList<String> bitStrings(int k) {
}

New Topic/Question
Reply


MultiQuote







|