Java Distance Calculate distance(String seq1, String seq2)

Here you can find the source of distance(String seq1, String seq2)

Description

find the number of places where the two given strings differ from each other

License

Apache License

Parameter

Parameter Description
seq1 a parameter
seq2 a parameter

Declaration

public static int distance(String seq1, String seq2) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from   w w w  . j a  v  a  2  s  . c  o  m
     * find the number of places where the two given strings differ from each
     * other
     * 
     * @param seq1
     * @param seq2
     * @return
     */
    public static int distance(String seq1, String seq2) {
        int count = 0;
        for (int i = 0; i < seq1.length(); i++) {
            if (seq1.charAt(i) != seq2.charAt(i)) {
                count++;
            }
        }

        return count;
    }
}

Related

  1. distance(int x1, int y1, int x2, int y2)
  2. distance(int xa, int ya, int xb, int yb)
  3. distance(int[] a, int[] b)
  4. distance(String a, String b)
  5. distance(String coord1, String coord2, char unit)
  6. distance2(float x, float y, float x1, float y1)
  7. distance2(float x1, float y1, float x2, float y2)
  8. distance2(int x1, int y1, int x2, int y2)
  9. distance2d(double x1, double y1, double x2, double y2)