Hey guys can you help me convert this code into java... i started a little...

def  minEditDistR(target, source):
   """ Minimum edit distance. Straight from the recurrence. """
 
   i = len(target); j = len(source)
 
   if i == 0:  return j
   elif j == 0: return i
 
   return(min(minEditDistR(target[:i-1],source)+1,
              minEditDistR(target, source[:j-1])+1,
              minEditDistR(target[:i-1], source[:j-1])+substCost(source[j-1], target[i-1])))
 
def substCost(x,y):
    if x == y: return 0
    else: return 2

Here is me trying

public static int distance (String s1, String s2){
		int a = s1.length(); 
		int b = s2.length();
 
		if ( a == 0) return b;
		if ( b == 0) return a;

Thank YOU!

Most of the people on this form don't know java and python so explain what your code is supposed to do then I will be able to help you.

There is also a java library called Jython for using java and python together if you don't have to convert your code for what you are doing but this is a simple piece of code you have posted so it will be simpler to convert it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.