Click to See Complete Forum and Search --> : Help


denlin
09-03-2003, 09:52 PM
How do I create a program like this with 'for' control?I tried to do it..but only succeeded in creating a rectangle instead of a triangle...what's wrong?

abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxy
abcdefghijklmnopqrstuvwx
abcdefghijklmnopqrstuvw
abcdefghijklmnopqrstuv
abcdefghijklmnopqrstu
abcdefghijklmnopqrst
abcdefghijklmnopqrs
abcdefghijklmnopqr
abcdefghijklmnopq
abcdefghijklmnop
abcdefghijklmno
abcdefghijklmn
abcdefghijklm
abcdefghijkl
abcdefghijk
abcdefghij
abcdefghi
abcdefgh
abcdefg
abcdef
abcde
abcd
abc
ab
a

Jona
09-03-2003, 10:52 PM
Instead of the more common for() loop that increments, you are in need of a loop that will decrement, thus it would look like this:


var abc="abcdefghijklmnopqrstuvwxyz";
for(i=0; i<27; i--){
// Code to remove the last letter from the variable
}
// Code to display it


[J]ona

denlin
09-05-2003, 02:05 AM
This is my code....how do I insert what you told me to do earlier?? Cos I tried to add it in..but it just can't work.
public class b {
public static void main(String[] args) {

for(int i = 0; i < 26; ++i)
{
// Print leading spaces
for(int j = -1; j < i; ++j)
System.out.print(" ");

// Print leading alphabets
for(char a = 'a'; a <= 'z'; ++a)

System.out.print(a);

//Start a new line
System.out.println(" ");
}
}
}

Jona
09-05-2003, 12:16 PM
Sorry, since you posted in the JavaScript forum, you have lead me to believe that you were doing this in JavaScript, not C (or C++).

[J]ona

denlin
09-08-2003, 10:57 AM
I was doing using javascript....but it's ok..cos I've solved my problem..Thanks anyway