-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
40 lines (35 loc) · 900 Bytes
/
Test.java
File metadata and controls
40 lines (35 loc) · 900 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
30
31
32
33
34
35
36
37
38
39
40
import java.util.Arrays;
public class Test {
public static int globalVar = 10;
public static double[] globalArr = new double[]{2.0, 4.5};
public static void main(String[] args) {
int i = 1;
int j = i * 2;
float f = 6.8f;
System.out.println(j);
int k = add(i, j);
System.out.println(k * globalVar);
String[] arr = getStringArray();
System.out.println(Arrays.toString(arr));
int sumOfFirst6 = sumOfFirstN(6);
System.out.println("Sum of first 6 = " + sumOfFirst6);
System.out.println("globalArr[0] = " + globalArr[0]);
}
public static int add(int x, int y) {
return x + y;
}
public static String[] getStringArray() {
String[] arr = new String[3];
arr[0] = "first";
arr[1] = "second";
arr[2] = "third";
return arr;
}
public static int sumOfFirstN(int x) {
if (x == 1) {
return x;
}
int recResult = sumOfFirstN(x - 1);
return x + recResult;
}
}