Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Return string from a method
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
umaza




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: 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));
joshm




PostPosted: 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";
        }
}
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: