can any one do this in a loop? (for loop)
Code :
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>
or just like this
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...
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(">");
}
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:
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(">");
}
}
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....:-? :-?