-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOOPSa11.java
More file actions
108 lines (90 loc) · 2.54 KB
/
OOPSa11.java
File metadata and controls
108 lines (90 loc) · 2.54 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import java.util.Scanner;
import java.util.Arrays;
public class OOPSa11 {
int [] arr=new int[10];
public void input() {
Scanner sc = new Scanner(System.in);
System.out.println("Enter 10 integers:");
for (int i = 0; i < 10; i++) {
arr[i] = sc.nextInt();
}
}
public void display()
{
System.out.println("Your Entered array is");
System.out.println(Arrays.toString(arr));
}
public void dis() {
int m=0;
for(int i=0;i<arr.length;i++)
{ if(arr[i]>m)
{
m=arr[i];
}
}
System.out.println("The maximum value of the array is "+m);
//return m;
}
public void displayValues() {
System.out.println("Array values:");
for (int value : arr) {
System.out.print(value + " ");
}
System.out.println();
}
public void avg()
{
int m=0;
for(int i=0;i<10;i++)
{
m=m+arr[i];
}
int avg=m/arr.length;
System.out.println("Average is"+avg);
//return avg;
}
public void acc()
{
Arrays.sort(arr);
System.out.println("Your Sorted array is");
displayValues();
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
OOPSa11 obj=new OOPSa11();
int choice;
do {
System.out.println("\nMenu:");
System.out.println("1. Input values into the array");
System.out.println("2. Display the values");
System.out.println("3. Display the largest value");
System.out.println("4. Display the average");
System.out.println("5. Sort the array in ascending order");
System.out.println("6. Exit");
System.out.print("Enter your choice: ");
choice = sc.nextInt();
switch (choice) {
case 1:
obj.input();
break;
case 2:
obj.displayValues();
break;
case 3:
obj.dis();
break;
case 4:
obj.avg();
break;
case 5:
obj.acc();
break;
case 6:
System.out.println("Exiting...");
break;
default:
System.out.println("Invalid choice. Please try again.");
}
} while (choice != 6);
}
}