find the maximum occur number in an integer Write a function named maxOccurDigit that returns the digit that
  occur the most. If there is no such digit,  it will return -1. For
  example maxOccurDigit(327277) would return 7 because 7 occurs three
  times in the number  and all other digits occur less than three times.
  
  Other examples:
  
  maxOccurDigit(33331) returns 3
  
  maxOccurDigit(3232, 6) returns -1
  
  maxOccurDigit(5) returns 5
  
  maxOccurDigit(-9895) returns 9
  
  The function signature is
  maxOccurDigit(int n)


I have done it this way:

public class checknumbers{
   public static void main(String[] args)  {
   System.out.println(maxOccurDigit(32332));
  }

 public static int maxOccurDigit(int a){
    String str2 = Integer.toString(a); // converts a into String
    char[] ch2 = str2.toCharArray(); //gets str2 into an array of char
    int[] t2 = new int[ch2.length];  //defines t2 for bringing ch2 into it
    for(int i=0;i&lt;ch2.length;i++){ //  ASCII table 
      t2[i]= (int) ch2[i]-48;   // ch2[i] is 48 units more than what we want
    }
    int count = 1, tempCount;
    int popular = t2[0];
    int temp = 0;
    for (int i = 0; i &lt; (t2.length - 1); i++){
    temp = t2[i];
    tempCount = 0;
    for (int j = 1; j &lt; t2.length; j++){
      if (temp == t2[j])
        tempCount++;
    }
    if (tempCount &gt; count){
      popular = temp;
      count = tempCount;
    }
  }
    return popular;
  } 
 }


How could I return -1 if there are two integers but methods have only one?
You are passed an integer parameter, and you have to return an integer.  I do not see it as worthwhile converting to a string for the counting.  Better to count the digits directly from the original integer.  MOD (%) 10 will give you the last integer, and DIV (/) 10 will shift the remainder along one position.

You may have to be careful with 0 and negative numbers with this method, otherwise you might get unexpected results.

As will as finding the most common digit you also have to find if there are any other digits with the same frequency.  As you look for a new higher maximum, look for other digits with the same count and keep a note if they exist.

This is my code:

public static int maxOccurDigit(int a) {

    // Zero is a special case.
    if (a == 0) {
        return 0;
    }

    // Numbers != 0.
    int[] digitCounts = new int[10];

    // Ensure a positive
    if (a &lt; 0) {
        a *= -1;
    }

    while (a &gt; 0) {
        digitCounts[a % 10] += 1;
        a /= 10;
    }

    // Find max count and occurrences.
    int maxCount = digitCounts[0];
    boolean sameCounts = false;
    int digit = 0;
    for (int i = 1; i &lt; digitCounts.length; i++) {
        if (digitCounts[i] &gt; maxCount) {
            maxCount = digitCounts[i];
            sameCounts = false;
            digit = i;
        } else if (digitCounts[i] == maxCount) {
            // Digits with equal counts.
            sameCounts = true;
        }
    }

    // Check for multiple max counts.
    if (sameCounts) {
        return -1;
    }

    // Valid single max digit
    return digit;

} // end maxOccurDigit()