Home > Archive > Java Help > July 2004 > USING LOOPS TO CREATE A PATTERN !
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
USING LOOPS TO CREATE A PATTERN !
|
|
| Jay Dean 2004-07-23, 3:57 am |
| Hi-
I am new to java and I would appreciate your help with a code
(method) using loops(while or for).It takes in an integer n, and
creates a triangle of n rows with alternating integers on each row.
Example 1: When n=4 the pattern below results:
...1...
..2.2..
.3.3.3.
4.4.4.4
Example 2: When n is say 3, the pattern below results:
..1..
.2.2.
3.3.3
I kind of see the pattern but can't seem to figure out how to
implement it with loops. I would appreciate any code that will help me
out.Thank you.
Jay Dean
| |
| Roedy Green 2004-07-23, 3:57 am |
| On 22 Jul 2004 23:49:21 -0700, fresh1700@yahoo.com (Jay Dean) wrote or
quoted :
>I kind of see the pattern but can't seem to figure out how to
>implement it with loops. I would appreciate any code that will help me
>out.Thank you.
One way of thinking of it is this:
each line contains N characters. I need a loop that runs N times, the
canonical for.
I need M lines, I need an outer loop for that.
Now my question to solve is given i (row number) and j (the column
number) what character should I print? Hint look at the % operator.
see http://mindprod.com/jgloss/modulus.html
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
|
|
|
|
|