Computer Science Canada

Return string from a method

Author:  umaza [ Wed Feb 22, 2012 10:44 pm ]
Post subject:  Return string from a method

How do I return string from a method, I tried following code bellow as a test, it compiles but it doesn't do anything

Turing:

public class TriangleCatFour
{
  public static void main (String[] args)
  {
    triangle(4,4,4);
  }
  public static String triangle(int side1, int side2, int side3)
  {
    return ("Triangle: equilateral and acute");
  }
}


I am just testing and before I progress, I want to be able to accomplish this.
I have an assignment and my final goal is: http://webteach.net/ics3u/methods/methodLab.html

Author:  Insectoid [ Wed Feb 22, 2012 10:46 pm ]
Post subject:  RE:Return string from a method

It's not doing anything because you're not doing anything with it. Try System.out.println(triangle(4,4,4));

Author:  joshm [ Thu Feb 23, 2012 10:46 am ]
Post subject:  Re: Return string from a method

Something like this
code:
public class TriangleCatFour
{
        private int s1;
        private int s2;
        private int s3;
        public static void main(String[] args)
        {
                TriangleCatFour triangle1 = new TriangleCatFour(4,4,4);
                System.out.println(triangle1);
        }
        public TriangleCatFour(int s1, int s2, int s3)
        {
                this.s1 = s1;
                this.s2 = s2;
                this.s3 = s3;
        }
        public String toString()
        {
                if(s1 == s2 && s1 == s3)
                        return "Triangle: equilateral and acute";
                else
                        return "Triangle: not equilateral and acute";
        }
}


: