mirror of
https://bitbucket.org/Mattrixwv/javaclasses.git
synced 2025-12-06 15:03:58 -05:00
Changed some primitive ints to Integer class
This commit is contained in:
@@ -168,7 +168,7 @@ public class Algorithms{
|
|||||||
return primes;
|
return primes;
|
||||||
}
|
}
|
||||||
//This function gets a certain number of primes
|
//This function gets a certain number of primes
|
||||||
public static ArrayList<Integer> getNumPrimes(int numberOfPrimes){
|
public static ArrayList<Integer> getNumPrimes(Integer numberOfPrimes){
|
||||||
ArrayList<Integer> primes = new ArrayList<Integer>(); //Holds the prime numbers
|
ArrayList<Integer> primes = new ArrayList<Integer>(); //Holds the prime numbers
|
||||||
Boolean foundFactor = false; //A flag for whether a factor of the current number has been found
|
Boolean foundFactor = false; //A flag for whether a factor of the current number has been found
|
||||||
|
|
||||||
@@ -304,7 +304,7 @@ public class Algorithms{
|
|||||||
return primes;
|
return primes;
|
||||||
}
|
}
|
||||||
//This function returns all factors of goalNumber
|
//This function returns all factors of goalNumber
|
||||||
public static ArrayList<Integer> getFactors(int goalNumber){
|
public static ArrayList<Integer> getFactors(Integer goalNumber){
|
||||||
//You need to get all the primes that could be factors of this number so you can test them
|
//You need to get all the primes that could be factors of this number so you can test them
|
||||||
Double topPossiblePrime = Math.ceil(Math.sqrt(goalNumber));
|
Double topPossiblePrime = Math.ceil(Math.sqrt(goalNumber));
|
||||||
ArrayList<Integer> primes = getPrimes(topPossiblePrime.intValue());
|
ArrayList<Integer> primes = getPrimes(topPossiblePrime.intValue());
|
||||||
@@ -504,7 +504,7 @@ public class Algorithms{
|
|||||||
return divisors;
|
return divisors;
|
||||||
}
|
}
|
||||||
//This function returns all the divisors of goalNumber
|
//This function returns all the divisors of goalNumber
|
||||||
public static Integer getFib(int goalSubscript){
|
public static Integer getFib(Integer goalSubscript){
|
||||||
//Setup the variables
|
//Setup the variables
|
||||||
Integer[] fibNums = {1, 1, 0}; //A list to keep track of the Fibonacci numbers. It need only be 3 long because we only need the one we are working on and the last 2
|
Integer[] fibNums = {1, 1, 0}; //A list to keep track of the Fibonacci numbers. It need only be 3 long because we only need the one we are working on and the last 2
|
||||||
|
|
||||||
@@ -559,7 +559,7 @@ public class Algorithms{
|
|||||||
return fibNums[(fibLoc - 1) % 3];
|
return fibNums[(fibLoc - 1) % 3];
|
||||||
}
|
}
|
||||||
//This function returns a list of all Fibonacci numbers <= goalNumber
|
//This function returns a list of all Fibonacci numbers <= goalNumber
|
||||||
public static ArrayList<Integer> getAllFib(int goalNumber){
|
public static ArrayList<Integer> getAllFib(Integer goalNumber){
|
||||||
//Setup the variables
|
//Setup the variables
|
||||||
ArrayList<Integer> fibNums = new ArrayList<Integer>(); //A list to save the Fibonacci numbers
|
ArrayList<Integer> fibNums = new ArrayList<Integer>(); //A list to save the Fibonacci numbers
|
||||||
|
|
||||||
@@ -626,7 +626,7 @@ public class Algorithms{
|
|||||||
return fibNums;
|
return fibNums;
|
||||||
}
|
}
|
||||||
//This function returns the sum of all elements in the list
|
//This function returns the sum of all elements in the list
|
||||||
public static int getSum(ArrayList<Integer> nums){
|
public static Integer getSum(ArrayList<Integer> nums){
|
||||||
//If a blank list was passed to the function return 0 as the sum
|
//If a blank list was passed to the function return 0 as the sum
|
||||||
if(nums.size() == 0){
|
if(nums.size() == 0){
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user