Problem output on screen with toString

0

Hello very good I have a main that calls a method to show the content of an object on the screen, the main is this:

     class Main
      {
         /**
           * main method
           * @param args arguments
           */
    public static void main(String args[])
    {

           //Create a result
    Result R = new Result("Ra.one",12,93,84);
    //display a result
            R.display();
      }
    }          

What I do in that method to prove that it's all right is to get a message on the screen and it does not return anything ... I do this:

              public String display() {

                 StringBuilder sb = new StringBuilder();
                 sb.append("Hola que tal como estamos " );

                return sb.toString();

}

He does not return anything to me, I do not understand why. The Display method wants me to behave like a toString.

    
asked by Roman345 27.11.2016 в 14:59
source

2 answers

1

As you have the code you will have to do:

System.out.println(R.display());

Or in your display() method include the line that shows it before the return :

System.out.println(sb.toString());
    
answered by 27.11.2016 / 15:24
source
1

Your method does not "display" a string, it just returns it. If you want to show a string in console, the common way is to use System.out , for example

            System.out.println("Hola");
    
answered by 27.11.2016 в 15:17