Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Help on patterns of **********

  Asked By: Jimmy    Date: Mar 14    Category: Java    Views: 628
  

Basically, when the user types in amount there will be a triangle
formed as follows with x determining the width of the first line. EG:
if i type in 10. The first line will be 10 stars, and the length will
be 5.

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

As you can see, the width of each line goes down by two each line -
that is intentional. However, I have no idea on how to push the stars
further to the right!

Here's my code: (or at least some of it!)

int x = 0 ;
int y = 0 ;

int count ;
int count2 ;
boolean done = true ;


while (done == true)
{
c.out.println("Enter value for x, you bam") ;
x = c.input.readInt() ;



if (x <= 0)
{
done = true ;


}
else
done = false ;
}

y = x ;

for (count = 1; count <= x ; count++)
{
for (count2 = 1; y >= count2; count2++)

c.out.print ("*") ;



y = y - 2 ; // not part of the for statement, it would seem
c.out.println (" ") ;



}
}

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Help on patterns of ********** Or get search suggestion and latest updates.




Tagged: