forked from ucsd-cse15l-w23/lab3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLectureExamples.java
More file actions
39 lines (36 loc) · 772 Bytes
/
LectureExamples.java
File metadata and controls
39 lines (36 loc) · 772 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
class MainExample1 {
public static void main(String[] args) {
int current = 0;
while(current < args.length) {
System.out.println(args[current]);
}
}
}
class MainExample2 {
public static void main(String[] args) {
int length = args.length;
for(int i = 0; i < length; length += 1) {
System.out.println(args[i]);
}
}
}
class EvensExample {
static int sumEvenIndices(int[] nums) {
int sum = 0;
for(int i = 0; i < nums.length; i += 2) {
sum += nums[i + 1];
}
return sum;
}
}
class NumsExample {
static double reciprocal(int n) {
return 1 / n;
}
static double ratio(int n, int d) {
return n / d;
}
static double formula(int a, int b, int c) {
return ratio(a, b) * reciprocal(c);
}
}