# Easy.

• September 26th, 2012, 08:15 AM
Totel
Easy.
I know this is easy to most of you. Even though I will be look stupid if
in my programs, I really don't know how to do it.

Output:
Quote:

*****
*****
*****
*****
*****
Code :

```public class Ex1 { public static void main (String args[]) {   int x = 0; int y = 0;   for(y=0;y<5;y++) { for(x=0;x<4;x++) { System.out.print("*"); } System.out.println("*"); }```

Output:
Quote:

*
**
***
****
*****
Code :

```public class Ex2 { public static void main (String args[]) {       for(int y=0;y<5;y++) { for(int x=0;x<y;x++) { System.out.print("*"); } System.out.println("*"); }   } }```

I made those simple codes on the upper. Now my problem is how can I make
an output like this, using for loop not just by simple System.out.print();

Quote:

............*
..........**
........***
......****
....*****
PS: The Periods/dots aren't included in output, I just can't move the
asterisk in those positions.
• September 26th, 2012, 08:35 AM
newbie
Re: Easy.
Using your Ex2 as a base for it, notice how for(int x = 0; x < y; x++) will never be true the first time around, as both x and y would equal 0. This is the cause for you needing to add that extra star after the loop.
A better approach would be to set the outer loop to begin at 1 and test for EQUAL TO and LESS THAN.

As you've already got Ex2 done, i'll give you a rework of it so that you can understand and better solve this next step.

Code java:

``` public static void main(String args[]) {   final int MAX_ROW = 5; final String ARROW = "->";   for (int row = 1; row <= MAX_ROW; row++) {   for (int col = 0; col < row; col++) { System.out.print("*"); } System.out.println(""); }   }```

Ofcourse the fix will be the same in both templates, I just hope you can try understand your problem better when values etc are clearer.
• September 26th, 2012, 09:59 AM
Totel
Re: Easy.
Quote:

Originally Posted by newbie
Using your Ex2 as a base for it, notice how for(int x = 0; x < y; x++) will never be true the first time around, as both x and y would equal 0. This is the cause for you needing to add that extra star after the loop.
A better approach would be to set the outer loop to begin at 1 and test for EQUAL TO and LESS THAN.

As you've already got Ex2 done, i'll give you a rework of it so that you can understand and better solve this next step.

Code java:

``` public static void main(String args[]) {   final int MAX_ROW = 5; final String ARROW = "->";   for (int row = 1; row <= MAX_ROW; row++) {   for (int col = 0; col < row; col++) { System.out.print("*"); } System.out.println(""); }   }```

Ofcourse the fix will be the same in both templates, I just hope you can try understand your problem better when values etc are clearer.

Using 2 for Loops and 2 SoP it's possible ?
• September 26th, 2012, 03:19 PM
newbie
Re: Easy.
You'll need 3 "SoP"s to complete it.