Question: StringsOfNumbers Write two recursive methods that generate string of numbers. The first method generates all the possible strings that contain the combinations of n bits,

StringsOfNumbers

Write two recursive methods that generate string of numbers. The first method generates all the possible strings that contain the combinations of n bits, where n is given by the user. The second method is generalization of the first method. It also generates all the permutations of n numbers, but the numbers are drown from [0..k); where the k is given by the user. See sample runs below. Implement the algorithms that you designed as part of your pre-lab.

public class StringsOfNumbers { /**  * bitString - a recursive function that generates strings of n bits  *  * @param n the number of digits  * @param str one permutation of the string to be constructed and printed  */  private static void bitString(String str, int n) { // TODO Project #2  // IMPLEMENT THIS RECURSIVE METHOD // STEP#1 Base case - the string is constructed so print it // STEP#2 recursive case - make two recursive calls: // one to append 0 and the second one to append 1 } /**  * bitString - a recursive function that generates strings of n digits [0..k)  *  * @param n the number of digits  * @param k k-1 should be the largest digit in the string str  * @param str one permutation of the string to be constructed and printed  */  private static void kString(String str, int n, int k) { // TODO Project #2  // IMPLEMENT THIS RECURSIVE METHOD } public static void main(String args[]) { Scanner input = new Scanner(System.in); System.out.println("Please enter an integer value of n representing the number of digits in a string"); int n = input.nextInt(); System.out.println(); System.out.println("Generating binary-Strings:"); bitString("", n); System.out.println(); System.out.println("Please enter an integer value k; strings of length n will be drown from 0..k-1"); int k = input.nextInt(); System.out.println("Generating k-Strings:"); kString("", n, k); } } 

SAMPLE RUN:

Please enter an integer value of n representing the number of digits in a string

3

Generating binary-Strings:

000

001

010

011

100

101

110

111

Please enter an integer value k; strings of length n will be drown from 0..k-1

4

Generating k-Strings:

000

001

002

003

010

011

012

013

020

021

022

023

030

031

032

033

100

101

102

103

110

111

112

113

120

121

122

123

130

131

132

133

200

201

202

203

210

211

212

213

220

221

222

223

230

231

232

233

300

301

302

303

310

311

312

313

320

321

322

323

330

331

332

333

Process finished with exit code 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!