Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PrimeNumbers {
- private static boolean multipleof3(int i) {
- int[] intDigits = String.valueOf(i).chars().map(Character::getNumericValue).toArray();
- int digitsum = IntStream.of(intDigits).sum();
- boolean multiple = digitsum %3 == 0;
- return multiple;
- }
- private static boolean multipleof2(int i) {
- int lastdigit = i%10;
- return lastdigit == 0 || lastdigit == 2 ||
- lastdigit == 4 || lastdigit == 6 || lastdigit == 8;
- }
- private static boolean multipleof5(int i) {
- int lastdigit = i%10;
- return lastdigit == 0 || lastdigit == 5;
- }
- private static boolean multipleof11(int i) {
- int sum_even_numbers = 0, sum_uneven_numbers = 0;
- int[] intDigits = String.valueOf(i).chars().map(Character::getNumericValue).toArray();
- for (Integer integer : intDigits) {
- if(integer%2==0) {
- sum_even_numbers = sum_even_numbers+integer;
- } else {
- sum_uneven_numbers = sum_uneven_numbers+integer;
- }
- }
- return sum_even_numbers+sum_uneven_numbers == 0;
- }
- /*private static boolean multipleof7(int i) {
- int[] intDigits = String.valueOf(i).chars().map(Character::getNumericValue).toArray();
- for (Integer integer : intDigits) {
- }
- }*/
- public static List<Integer> calculateprimes(int i, Player p) {
- List<Integer> primeslist = new ArrayList<Integer>();
- if (i <= 0) {
- p.sendMessage(Utils.chat("&c»» prime numbers must be 0 or below."));
- } else if (i == 1) {
- primeslist.add(1);
- } else {
- for (int increase = 0; increase <= i ; increase++) {
- if (multipleof2(increase)) {
- primeslist.add(increase);
- } else if(multipleof3(increase)) {
- primeslist.add(increase);
- } else if(multipleof5(increase)) {
- primeslist.add(increase);
- } else if(multipleof11(increase)) {
- primeslist.add(increase);
- } else {
- for (int g = 7; g < increase/2; g++) {
- boolean foundprimes = false;
- if(increase%g == 0) {
- break;
- } else if(g==increase-1) {
- primeslist.add(increase);
- }
- }
- }
- }
- }
- return primeslist;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement