mirror of
https://github.com/RustyRaptor/CS-272.git
synced 2026-12-03 15:55:22 -07:00
Progress Lab 10
This commit is contained in:
1 parent
bdd9485c1a
commit
dc6bd5c19f
1 file changed
+23
-1
@@ -2,7 +2,7 @@ import java.util.Arrays;
|
||||
|
||||
public class RecursiveQuestion {
|
||||
public static void main(String[] args) {
|
||||
for (int i = 0; i < 20; i++) {
|
||||
for (int i = 0; i < 201; i++) {
|
||||
System.out.print(FibBinaryRecursive(i));
|
||||
System.out.print(", ");
|
||||
}
|
||||
@@ -91,6 +91,28 @@ public class RecursiveQuestion {
|
||||
}
|
||||
}
|
||||
|
||||
public static String pattern(String outs, int n, int i)
|
||||
{
|
||||
int na = (int)(Math.log(n)/Math.log(2));
|
||||
if (na == 0)
|
||||
{
|
||||
StringBuilder outsBuilder = new StringBuilder(outs);
|
||||
for (int k = 0; k < i; k++) outsBuilder.append(' ');
|
||||
for (int k = 0; k < n; k++) outsBuilder.append("* ");
|
||||
outs = outsBuilder.toString();
|
||||
return outs+= '\n';
|
||||
}
|
||||
else
|
||||
{
|
||||
outs = pattern(outs,(int)(Math.pow(2.0,na - 1)),i);
|
||||
for (int k = 0; k < i; k++) outs += ' ';
|
||||
for (int k = 0; k < n; k++) outs += "* ";
|
||||
outs+= '\n';
|
||||
i+= na * 2;
|
||||
return outs = pattern(outs,(int)(Math.pow(2.0,na - 1)),i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* recursive function to calculate factorial
|
||||
* @param n the integer you want to calculate the factorial of.
|
||||
|
||||
Reference in new issue
Block a user