Results 1 to 2 of 2

Thread: returning multiple items

  1. #1
    Join Date
    Jan 2007
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default returning multiple items

    if i needed to make a method to get a full name and return first and last names would i do it somehting like this?

    Code:
    public String getFullName
    {
     return firstName;
     return lastName;
    or 
     return firstName lastName
    }
    assuming they were defined else where how would i return both items?

  2. #2
    Join Date
    Feb 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    A method usually terminates when the statment is returned. You will need to encapsulate the two objects. Java only allows you to return one type.

    public int returnNP(int V){
    n = -F/E;
    int P = (n*R*T)/V;
    // ideal gas Law

    Return n, P; // will not work
    }
    int[] nAndP = new int[];
    public int [] returnNR(int V){
    n = -F/E;
    int P = (n*R*T)/V;
    // ideal gas Law
    nAndP[0] = n;
    nAndP[1] = P;
    Return nAndP; // will work
    }

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •