Java初学,Eclipse:如何调用方法? (简单的)

Beginner in Java, Eclipse: How call method? (simple)

我是 Java 的初学者(新手)。我已经下载了 Eclipse 环境以能够编码和 运行 Java 程序。现在我的问题很简单:我正在尝试 运行 下面的代码,特别是我想计算两个词之间所谓的 编辑距离 。我不知道如何向这段代码插入输入(很简单吧!)。举个例子w1=labdw2=bladw1len=4w2len=4。如何将其作为参数插入到我的函数中?

代码

int partDist(String w1, String w2, int w1len, int w2len) {
    if (w1len == 0)
      return w2len;
    if (w2len == 0)
      return w1len;
    int res = partDist(w1, w2, w1len - 1, w2len - 1) + 
    (w1.charAt(w1len - 1) == w2.charAt(w2len - 1) ? 0 : 1);
    int addLetter = partDist(w1, w2, w1len - 1, w2len) + 1;
    if (addLetter < res)
      res = addLetter;
    int deleteLetter = partDist(w1, w2, w1len, w2len - 1) + 1;
    if (deleteLetter < res)
      res = deleteLetter;
    return res;
  }

我应该在代码末尾添加一些命令然后 运行 它吗?对于这种特殊情况,那会是什么?

将函数 'partDist' 与主函数一起放在 class 中,并从主函数调用它,如下所示:

    class YourMainClass{
    public static void main(String args[]){
       System.out.println(partDist("labd", "blad", 4, 4)); // inorder to print the result to console
    }
    int partDist(String w1, String w2, int w1len, int w2len) {
    if (w1len == 0)
      return w2len;
    if (w2len == 0)
      return w1len;
    int res = partDist(w1, w2, w1len - 1, w2len - 1) + 
    (w1.charAt(w1len - 1) == w2.charAt(w2len - 1) ? 0 : 1);
    int addLetter = partDist(w1, w2, w1len - 1, w2len) + 1;
    if (addLetter < res)
      res = addLetter;
    int deleteLetter = partDist(w1, w2, w1len, w2len - 1) + 1;
    if (deleteLetter < res)
      res = deleteLetter;
    return res;
  }
  }