-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1-D Array Address.java
31 lines (28 loc) · 1.04 KB
/
1-D Array Address.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
//WAP TO FIND ABSE ADDRESS OF i th ELEMENT THE USER PROVIDES FOR ARRAY
//1-D ARRAY
import java.util.*;
class ex1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the size of an array: ");
int n = sc.nextInt();
System.out.println("Enter the Base value address: ");
int b = sc.nextInt();
System.out.println("Enter the datatype size(W)");
int w = sc.nextInt();
System.out.println("Enter the LowerBound Index Value: ");
int lb = sc.nextInt();
System.out.println("Enter [i] position of element for which you want to find the address: ");
int i = sc.nextInt();
if (i >= lb) {
if (i <= n) {
int ans = b + ((i - lb) * w);
System.out.println("Address of [" + i + "] is " + ans);
} else {
System.out.println("Invalid Argument !!");
}
} else {
System.out.println("Invalid Argument !!");
}
}
}