-1

import static java.lang.System.*;

public class TriangleOne
{
    private String word;

    public TriangleOne()
    {
        word="";
    }

    public TriangleOne(String s)
    {
        word = s;
    }

    public void setWord(String s)
    {
        word = s;
    }

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

This is the runner.

import static java.lang.System.*;

public class TriangleOneRunner
{
    public static void main ( String[] args )
    {
        TriangleOne test = new TriangleOne();
        test.setWord("hippo");
        System.out.println(test);

    }
}

This prints out 'TriangeOne@1e9c23b' I want this to print out

hippo
hipp
hip
hi
h

What should I fix?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Sean
  • 7
  • 1
  • 4

1 Answers1

0

You should be calling test.print() and not System.out.print()

Vinit Pillai
  • 518
  • 6
  • 17
  • Your welcome. Also do some research before starting to learn java the link given by @Kayaman – Vinit Pillai Feb 03 '20 at 15:51
  • 1
    Don't start at tutorialspoint. It's very unreliable (in some places it's absolutely awful, there are other unreliable tutorial sites like that too). Trust only the official tutorial. – Kayaman Feb 03 '20 at 15:53
  • Oh! then my bad. Will surely keep this in mind. Thanks @Kayaman. – Vinit Pillai Feb 03 '20 at 15:54