-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJavaCode.java
More file actions
29 lines (26 loc) · 1008 Bytes
/
Copy pathJavaCode.java
File metadata and controls
29 lines (26 loc) · 1008 Bytes
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
class JavaCode {
final static int MAXSIZE = 10;
private native int sumsquaredc(int arr[]);
public static void main(String args[]) {
System.out.println("-- We are in the Java program JavaCode --");
JavaCode c = new JavaCode();
int arr[] = new int[MAXSIZE];
System.out.println("Initialize the array arr[]");
for (int i=0; i<MAXSIZE; i++) {
arr[i] = i;
System.out.println(i + " " + arr[i]);
}
System.out.println("Call the C code");
int sum = c.sumsquaredc(arr);
System.out.println("-- We are back in Java --");
System.out.println("Contents of arr[]");
for (int i=0; i<MAXSIZE; i++)
System.out.println(i + " " + arr[i]);
System.out.println("Sum of squares in arr[] = " + sum);
System.out.println("Exit Java");
}
static {
// Call up the static library libmycodeinc.so created from ccode.c
System.loadLibrary("mycodeinc");
}
}