473,387 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

i can't get this recursion method to work

i have a program where a user can input a number and that number creates a pattern of asterisks for example if the number is four it looks like this


*
**
*
****
*
**
*

and eight looks like this

*
**
*
****
*
**
*
********
*
**
*
****
*
**
*

the problems is i can't figure out how to get the spacing to work
here is my code


package recursion;

public class recurse
{ private String temp = "";
private int line = 0;


public void tower(int n)
{
if (n == 1)
{



temp += "*";
System.out.println(temp);
temp = ""; }

else
{

tower((n+1)/2);



for (int x = 0; x < n; x++)
{ temp += "*"; }
space = n;
line++;
System.out.println(temp);
temp = "";

tower((n+1)/2);



}

}


}


when i run the program with the number being 8 i get this
*
**
*
****
*
**
*
********
*
**
*
****
*
**
*

I think the answer is simple but i dunno
May 23 '07 #1
1 1149
nevermind i figured it out
May 23 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Lowell Kirsh | last post by:
I'm trying to emulate the sorted() method introduced in python 2.4. The only difference is that it takes a sequence as one of its arguments rather than being a method of the sequence class. Does my...
11
by: Ken | last post by:
Hello, I have a recursive Sierpinski code here. The code is right and every line works fine by itself. I wish for all of them to call the function DrawSierpinski. But in this cae it only calls...
44
by: Bamber | last post by:
Why does f get returned ? (compiled with gcc). #include<stdio.h> int func(int a); main() { int f; f=func(7); printf("f=%d",f);
10
by: paulw | last post by:
Hi Please give problems that "HAS TO" to use recursion (recursive calls to itself.) Preferrably real world examples, not knights tour. I'm thinking about eliminating the use of stack... ...
0
by: Jack Addington | last post by:
I have a tree view object that I am trying to load via database calls. I'm trying to make it generic so that I can extend and re-use it. One of the things I want to be able to do is to load the...
19
by: Kay Schluehr | last post by:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691
6
by: Andre Kempe | last post by:
hej folks. i have a heap with fixed size and want to determine the depth of a element with given index at compile-time. therefore i wrote some templates. however, when i use template...
10
by: elventear | last post by:
Hello everyone, I am runing into recursion limit problems. I have found that the culprit was related to the __hash__ function that I had assigned to the objects that were added to a set. ...
20
by: athar.mirchi | last post by:
..plz define it.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.