I am working on this editDistance program in Java, but I cant figure out how to return the new strings.....
The program is returning the editDistance, but everytime a char doesnt match I want to delete it out of the string, in the end when I call printDistance(), I want to print the new Strings as well
import java.io.*;
import java.util.Scanner;
/**
*
* @author tricket_7
*/
public class NormalizedEditDistance {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
// TODO code application logic here
//Get the files
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the first file: ");
String filename1 = keyboard.nextLine();
System.out.println("Enter the second file: ");
String filename2 = keyboard.nextLine();
//Open file 1
File file1 = new File(filename1);
Scanner inputFile1 = new Scanner(file1);
//Read file 1
String str1 = inputFile1.nextLine();
//Open file2
File file2 = new File(filename2);
Scanner inputFile2 = new Scanner(file2);
String str2 = inputFile2.nextLine();
//Close the file
inputFile1.close();
inputFile2.close();
for (int i = 1; i < args.length; i += 2)
printDistance(args[i - 1], args[i]);
printDistance(str1, str2);
}
public static int getDistance(String s, String t){
int m = s.length();
int n = t.length();
int[][]dist = new int[m+1][n+1];
for(int i = 0;i <= m;i++){
dist[i][0] = i;
}
for(int j = 0;j <= n;j++){
dist[0][j] = j;
}
for(int j = 1;j <= n;j++){
for(int i = 1;i <= m;i++){
if(s.charAt(i-1) != t.charAt(j-1)){
dist[i][j] = minDistance((dist[i-1][j]+1),(dist[i][j-1]+1),(dist[i-1][j-1]+1));
}
else{
dist[i][j] = dist[i-1][j-1];
}
}
}
return(dist[m][n]);
}
public static int minDistance(int a,int b,int c){
return(Math.min(Math.min(a,b),c));
}
public static void printDistance(String s, String t) {
System.out.println(getDistance(s, t));
}
}