Created
September 19, 2019 01:52
-
-
Save ssysm/ed699c397c4a4b3f293a7395cc4edc16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
public class DistinctPowers{ | |
//Check if number exist in array | |
private static boolean isNumberExist(ArrayList<Double> arr, double cmp){ | |
for(double d: arr){ | |
if(d == cmp){ | |
return true; | |
} | |
} | |
return false; | |
} | |
public static void main(String[] args) throws ParseException{ | |
int a_min_base = 2; | |
int a_max_base = 100; | |
int b_min_power = 2; | |
int b_max_power = 100; | |
ArrayList<Double> products = new ArrayList<Double>(); | |
// compute and popluate array | |
for(int base = a_min_base; base <= a_max_base; base++){ | |
for(int pow = b_min_power; pow <= b_max_power; pow++){ | |
double prod = Math.pow(base, pow);// compute product | |
if(!isNumberExist(products,prod)){ // does number exist? | |
products.add(prod); // push to array | |
} | |
} | |
} | |
System.out.println(products.size()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment