-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInnerClass.java
58 lines (44 loc) · 1.24 KB
/
InnerClass.java
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
46
47
48
49
50
51
52
53
54
55
56
57
58
/* THIS IS A PROGRAM FOR INNER CLASS DEMONSTRATION */
class ICDemo {
int nums[];
ICDemo(int n[]) { //parameterised contructor
this.nums = n;
}
void analyze() {
inner ob1 = new inner();
System.out.println("The minimum element is : " + ob1.min());
System.out.println("The maximum element is : " + ob1.max());
System.out.println("The average is : " + ob1.avg());
}
class inner {
int min() {
int mini = nums[0];
for (int i = 0; i < nums.length; ++i) {
if (nums[i] < mini)
mini = nums[i];
}
return mini;
}
int max() {
int maxi = nums[0];
for (int i = 0; i < nums.length; ++i) {
if (nums[i] > maxi)
maxi = nums[i];
}
return maxi;
}
int avg() {
int sum = 0;
for (int i = 0; i < nums.length; ++i)
sum += nums[i];
return sum / nums.length;
}
}
}
class InnerClass {
public static void main(String[] args) {
int nums[] = { 25, 11, 90, 45, 80, 21, 34 };
ICDemo ic = new ICDemo(nums);
ic.analyze();
}
}