can any one do this in a loop? (for loop)

• October 3rd, 2009, 09:24 AM
chronoz13
can any one do this in a loop? (for loop)
Code :

```>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>> >>>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>> >>>>>> >>>>> >>>> >>> >> >```

or just like this

Code :

```>>>>> >>>> >>> >> >```

all of those you see are just a simple character '>' (greater than)

can anyone do this in a for loop?..
please im having some hard time thinking on how to diplay this...
• October 3rd, 2009, 12:35 PM
helloworld922
Re: can any one do this in a loop? (for loop)
Easy, just have a for loop count backwards. However, to do it in one for loop is kind of hard (though not impossible)

Code :

```for (int i = 10; i > 0; i--) { for (int j = i; j > 0; j--) { System.out.print(">"); } System.out.println(""); }```

Code :

```int n = 10; for(int i = (n*n+n)/2; i > 0; i--) { if (i*2%(n*n+n)==0) { n--; System.out.print("\n>"); } System.out.print(">"); }```
• October 4th, 2009, 06:24 AM
chronoz13
Re: can any one do this in a loop? (for loop)
i can understand the second code a little bit . but i cant resolve this problem 'ArithmeticException'
:confused:
• October 4th, 2009, 11:26 AM
helloworld922
Re: can any one do this in a loop? (for loop)
oops... flawed logic :P I was only checking if something was divisible by (n^2+n)/2, not equal to it.

Code :

``` int n = 10; for (int i = (n * n + n) / 2; i > 0; i--) { if (i == (n * n + n) / 2) { n--; System.out.print("\n>"); } else { System.out.print(">"); } }```
• October 4th, 2009, 09:31 PM
chronoz13
Re: can any one do this in a loop? (for loop)
you're really awesome when it comes in algorithms... lol :)) tnx !!

any way you said that this is possible in just one single for-loop...

hmm....:-? :-?