-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoop36.java
41 lines (34 loc) · 1.07 KB
/
oop36.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
import java.util.Scanner;
class Arra {
public void Access(int n) {
Scanner scr = new Scanner(System.in);
int[] arr = new int[100];
for (int i = 1; i <= n; i++) {
System.out.println("Enter the element at index " + i + " = ");
arr[i] = scr.nextInt();
}
int j = 0;
boolean flag = true;
while (flag && j<5 ){
try {
System.out.println("Enter the value of index");
int a = scr.nextInt();
System.out.println("The value at index is = "+arr[a]);
} catch (Exception e) {
System.out.println("Wrong!!");
j++;
}
}
if(j>=5){
System.out.println("Error");
}
}
}
public class oop36 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Arra arra = new Arra();
System.out.println("Enter the number of elements you want in an array");
arra.Access(sc.nextInt());
}
}