Question: JAVA: I needed help creating a method that will generate a sparse table, without using for or while loops or creating any additional methods I'll
JAVA:
I needed help creating a method that will generate a sparse table, without using for or while loops or creating any additional methods
I'll post the code that's given and ask the question at the end in bold:
public static long random(long n){ if (n == 0){ return 1; } return (random(n/4))+(random(3*n/4));
public static void exampleTable(int a, int z)
long exampleOne = random(a); System.out.println(a+" "+exampleOne);
if (start != end){ exampleTable(a+1, z); }
I'll then have a tester that will input values for example from 13 to 20.
Right now it would print out:
13 15
14 15
15 18
16 21
17 21
18 21
19 21
20 24
WHAT I NEED THE OUTPUT TO BE IS:
13 15
15 18
16 21
20 24
I need to know how to skip over duplicate values and get the output I just listed. Again, I can't use any loops, or whiles, or create any additional methods.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
