Skip to content

Commit d130397

Browse files
author
AkshatDobriyal
committed
added soundex algo
1 parent b48d086 commit d130397

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

Soundex Algorithm/Soundex.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
package soundex;
2-
3-
import java.util.Scanner;
4-
51
public class Soundex {
62

7-
public static String soundex(String str) {
3+
public static void soundex(String str) {
84

95
char[] s = str.toUpperCase().toCharArray();
106
//retaining first letter
@@ -30,7 +26,7 @@ public static String soundex(String str) {
3026
case 'Z':
3127
s[i] = '2';
3228
break;
33-
29+
3430
case 'D':
3531
case 'T':
3632
s[i] = '3';
@@ -64,15 +60,18 @@ public static String soundex(String str) {
6460

6561
// right padding with zeroes or truncating
6662
output = output + "0000";
67-
return output.substring(0, 4);
63+
System.out.println(str + " : " + output.substring(0, 4));
6864
}
6965

7066
public static void main(String[] args) {
7167

72-
Scanner sc = new Scanner(System.in);
73-
System.out.println("Enter the string");
74-
String str = sc.nextLine();
75-
String str_output = soundex(str);
76-
System.out.println(str_output);
68+
String str1 = "Dear";
69+
String str2 = "Deer";
70+
String str3 = "Ashcraft";
71+
String str4 = "Ashcroft";
72+
soundex(str1);
73+
soundex(str2);
74+
soundex(str3);
75+
soundex(str4);
7776
}
78-
}
77+
}

0 commit comments

Comments
 (0)