View Full Version : returning multiple items

01-31-2007, 02:19 AM
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?

public String getFullName
return firstName;
return lastName;
return firstName lastName

assuming they were defined else where how would i return both items?

Neural Network
02-08-2007, 10:07 PM
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