-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRangeFun.java
More file actions
62 lines (54 loc) · 1.48 KB
/
RangeFun.java
File metadata and controls
62 lines (54 loc) · 1.48 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import java.util.Arrays;
public class RangeFun {
// range function in which there is only the end required and it starts from 0:
public int[] range(int end){
int e = end;
int[] range = new int[(e)];
int i=0;
for(int n = 0 ; n < e ; n++){
range[i] = n;
i++;
}
return range;
}
// range function in which starting and ending values are given as parameters:
public int[] range(int start, int end){
int s = start;
int e = end;
int[] range = new int[e - s];
int i=0;
for(int n = s ; n < e ; n++){
range[i] = n;
i++;
}
return range;
}
public int[] range(int start, int end, int step){
int s = start;
int e = end;
int stp = step;
int[] range = new int[(e - s)/stp];
int i=0;
for(int n = s ; n < e ; n+=stp){
range[i] = n;
i++;
}
return range;
}
public static void main(String[] args) {
RangeFun run1 = new RangeFun();
System.out.println(Arrays.toString(run1.range(5,10)));
System.out.println();
for(int i:run1.range(10, 100)){
System.out.println(i);
}
System.out.println();
for(int i:run1.range(100)){
System.out.println(i);
}
System.out.println();
for(int i:run1.range(2, 100,2)){
System.out.println(i);
}
}
}