Soldato
- Joined
- 14 Dec 2005
- Posts
- 12,488
- Location
- Bath
I've hit a brick wall
. I've got a char array, called word, which funnily enough contains a word and I'm playing around doing different things with it.
One thing I've done is this:
So if for example the word in the array was Hello it'll output:
Another thing I've done is print it out a character at a time but starting from the end:
Using the same example of Hello that outputs:
What I'd like to do next is a combination of the two. I'd like it to output the last character, then the last two characters, etc. Maybe I'm just tired and lacking in coffee, but I just can't figure it out!
Using the same example the output should be:
Can anyone show me the light? I've been fiddling around for a while now and can't get it to work
. I've stuck them both into a java file here if anyone wants to play around, but TBH it's the logic of how to do it I'm lacking!
Cheers

One thing I've done is this:
Code:
for (int row = 0; row < word.length; row++)
{
for (int count = 0; count <= row; count++)
{
System.out.print(word[count]);
}
System.out.println();
}
So if for example the word in the array was Hello it'll output:
H
He
Hel
Hell
Hello
Another thing I've done is print it out a character at a time but starting from the end:
Code:
for (int i = word.length - 1; i >= 0; i--)
{
System.out.println(word[i]);
}
o
l
l
e
H
What I'd like to do next is a combination of the two. I'd like it to output the last character, then the last two characters, etc. Maybe I'm just tired and lacking in coffee, but I just can't figure it out!
Using the same example the output should be:
o
ol
oll
olle
olleH
Can anyone show me the light? I've been fiddling around for a while now and can't get it to work

Cheers
Last edited: