-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReturnMultiple.java
More file actions
45 lines (38 loc) · 1.13 KB
/
ReturnMultiple.java
File metadata and controls
45 lines (38 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// encapsulate all returned types into a class and then return an object of that class.
import java.util.*;
class MultiDivAdd {
int mul; // To store multiplication
double div; // To store division
int add; // To store addition
MultiDivAdd(int m, double d, int a)
{
mul = m;
div = d;
add = a;
}
}
class ReturnMultiple {
static MultiDivAdd getMultDivAdd(int a, int b)
{
// Returning multiple values of different
// types by returning an object
return new MultiDivAdd(a * b, (double)a / b, (a + b));
}
public static List<Object> getDetails()
{
String name = "Geek";
int age = 35;
char gender = 'M';
return Arrays.asList(name, age, gender);
}
// Driver code
public static void main(String[] args)
{
MultiDivAdd ans = getMultDivAdd(10, 20);
System.out.println("Multiplication = " + ans.mul);
System.out.println("Division = " + ans.div);
System.out.println("Addition = " + ans.add);
List<Object> person = getDetails();
System.out.println(person);
}
}