Hello,
i am new to java and i am not able to do the following program. If anybody can help me it will be very helpful to me. the program is to be done without using array . the program question is
" use a method named design which states a integer argument between 1 and 9 and print the following matter as shown below
ex: for integer argument = 4
- abcdcba
-
abc cba
-
ab ba
-
a a
-
ab ba
-
abc cba
-
abcdcba
If you interpret that little square a an x,y grid with 0,0 in the middle of that square,
and the square has size 2*N-1 (N given by the user) you can loop in both directions
in the range [-N+1, N-1] (e.g. N == 4, loop in the range [-3, 3]).
Ignoring those spaces for the moment you have to print the character
'a'+N-1-abs(x), i.e. the y value has nothing to do with it.
For the spaces, have a look at the upper right quadrant: if abs(y) <= 2-abs(x) you
must print a space instead. (it's simple linear algebra).
You can put two nested loops together (one for x and one for y) and apply the
logic I sketched above in the body of the innermost loop.
kind regards,
Jos