problem_33.java
private static int findCommonDigit(int top, int bottom) {
    String num = String.valueOf(top);
    String denom = String.valueOf(bottom);

    int commonDigit = -1;
    for(int i = 0; i < num.length(); i++) {
      if(denom.contains(String.valueOf(num.charAt(i)))) {
        int digit = Character.getNumericValue(num.charAt(i));

        if(digit != 0)  commonDigit = digit;
      }
    }
    return commonDigit;
  }
//Method to find the non-zero common digit of the numerator and denominator:
Method to find the non-zero common digit of the numerator and denominator.
Method to find the non - zero common digit of the numerator and denominator .
private static int findCommonDigit(int top, int bottom) {
    String num = String.valueOf(top);
    String denom = String.valueOf(bottom);
    int commonDigit = -1;
    for(int i = 0; i < num.length(); i++) {
      if(denom.contains(String.valueOf(num.charAt(i)))) {
        int digit = Character.getNumericValue(num.charAt(i));
        if(digit != 0)  commonDigit = digit;
      }
    }
    return commonDigit;
  }
private static int findCommonDigit ( int top , int bottom ) { String num = String . valueOf ( top ) ; String denom = String . valueOf ( bottom ) ; int commonDigit = - 1 ; for ( int i = 0 ; i < num . length ( ) ; i ++ ) { if ( denom . contains ( String . valueOf ( num . charAt ( i ) ) ) ) { int digit = Character . getNumericValue ( num . charAt ( i ) ) ; if ( digit != 0 ) commonDigit = digit ; } } return commonDigit ; }
Method to find the non-zero common digit of the numerator and denominator:
Method to find the non - zero common digit of the numerator and denominator :