Ad
Code
Diff
  • import java.util.Arrays;
    
    public class Kumite {
      public static int powerOfPrimes(int num) {
    
        String numStr = Integer.toString(num);
    
        int sumEven = 0;
        int sumOdd = 0;
        int exponent = 0;
    
        for (int i = 0; i < numStr.length(); i++) {
          
          int digit = Character.getNumericValue(numStr.charAt(i));   
          
          if(digit % 2 == 0) {
            sumEven += digit;
          } else {
            sumOdd += digit;
          }
    
          int[] primes = {2, 3, 5, 7};
          
          if(Arrays.binarySearch(primes, digit) >= 0) {
            exponent ++;
          }  
        }
    
        return (int) Math.pow(sumEven - sumOdd, exponent);
      }
    }
    
    
    • import java.util.Arrays;
    • public class Kumite {
    • public static int powerOfPrimes(int num) {
    • String numStr = Integer.toString(num);
    • int sumEven = 0;
    • int sumOdd = 0;
    • int base = 0;
    • int exponent = 0;
    • for (int i = 0; i < numStr.length(); i++) {
    • int digit = Character.getNumericValue(numStr.charAt(i));
    • if(digit % 2 == 0) {
    • sumEven += digit;
    • } else {
    • sumOdd += digit;
    • }
    • int[] primes = {2, 3, 5, 7};
    • if(Arrays.binarySearch(primes, digit) >= 0) {
    • exponent ++;
    • }
    • }
    • base = sumEven - sumOdd;
    • }
    • return (int) Math.pow(base, exponent);
    • return (int) Math.pow(sumEven - sumOdd, exponent);
    • }
    • }
Code
Diff
  • import java.util.Arrays;
    
    public class Kumite {
      public static int powerOfPrimes(int num) {
    
        String numStr = Integer.toString(num);
    
        int sumEven = 0;
        int sumOdd = 0;
        int base = 0;
        int exponent = 0;
    
        for (int i = 0; i < numStr.length(); i++) {
          
          int digit = Character.getNumericValue(numStr.charAt(i));   
          
          if(digit % 2 == 0) {
            sumEven += digit;
          } else {
            sumOdd += digit;
          }
    
          int[] primes = {2, 3, 5, 7};
          
          if(Arrays.binarySearch(primes, digit) >= 0) {
            exponent ++;
          }  
        }   
        base = sumEven - sumOdd;
    
        return (int) Math.pow(base, exponent);
      }
    }
    
    
    • import java.util.Arrays;
    • public class Kumite {
    • public static int powerOfPrimes(int num) {
    • String numStr = Integer.toString(num);
    • int sumEven = 0;
    • int sumOdd = 0;
    • int base = 0;
    • int exponent = 0;
    • int result = 0;
    • for (int i = 0; i < numStr.length(); i++) {
    • int digit = Character.getNumericValue(numStr.charAt(i));
    • if(digit % 2 == 0) {
    • sumEven += digit;
    • } else {
    • sumOdd += digit;
    • }
    • int[] primes = {2, 3, 5, 7};
    • if(Arrays.binarySearch(primes, digit) >= 0) {
    • exponent ++;
    • }
    • }
    • base = sumEven - sumOdd;
    • result = (int) Math.pow(base, exponent);
    • return result;
    • return (int) Math.pow(base, exponent);
    • }
    • }

You must create a function that receives an int number as a parameter.

The sum of the even digits and the sum of the odd digits must be performed.

powerOfPrimes(123) => 4

Then the results of the sums will be subtracted and that result will be raised to the number of prime numbers that has the initial int number.

Note: 1 is not considered prime.

import java.util.Arrays;

public class Kumite {
  public static int powerOfPrimes(int num) {

    String numStr = Integer.toString(num);

    int sumEven = 0;
    int sumOdd = 0;
    int base = 0;
    int exponent = 0;
    int result = 0;

    for (int i = 0; i < numStr.length(); i++) {

      int digit = Character.getNumericValue(numStr.charAt(i));
      
      if(digit % 2 == 0) {
        sumEven += digit;
      } else {
        sumOdd += digit;
      }

      int[] primes = {2, 3, 5, 7};
      
      if(Arrays.binarySearch(primes, digit) >= 0) {
        exponent ++;
      }
      
    }
    
    base = sumEven - sumOdd;
    result = (int) Math.pow(base, exponent);

    return result;
  }
}