Dylan
Dylan

Reputation: 11

I need to make a string triangle with for loops taking off one letter of the word each time. Java

I've been working on the code, but the only thing i can get in the output is a box with the word that i put in. For example i need to enter the word "hippo" to make this shape

This is what i have done so far on the for loop.

for(int i = length; i > 0 ; i--)
    {
        out.println(word);
    }

I need help please.

Upvotes: 0

Views: 1333

Answers (1)

ssantos
ssantos

Reputation: 16536

Off the top of my head, the loop would look something like this.-

for(int i = length - 1; i >= 0 ; i --) {
    System.out.println(word.substring(0, i));
}

Upvotes: 1

Related Questions