-
Notifications
You must be signed in to change notification settings - Fork 0
/
Basics.java
50 lines (42 loc) · 1.27 KB
/
Basics.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.util.ArrayList;
import java.util.Arrays;
public class Basics {
//print 1-255
public ArrayList printAllInRange(int int1, int int2){
ArrayList<Integer> newArray = new ArrayList<Integer>();
int i = int1;
while(i < int2){
newArray.add(i);
i++;
}
return newArray;
}
// print odds
public int[] printOdds(int number){
//setting i to zero
int i = 0;
//setting x to the number we feed printOdds in testing
int x = number;
//initializing an array
int[] oddArray;
//now we have to set how long we want the array
//otherwise we will have no positions - x is the number of positions the array will have
oddArray = new int[x];
while(i < x){
//this is setting the number of i to be 1 + the position we have initally given it
oddArray[i] = i + 1;
i++;
}
return oddArray;
}
//print sum
public int getSum(int number1, int number2){
int i = number1;
int sum = 0;
while(i < number2){
sum += i;
i++;
}
return sum;
}
}