Hi Folks,
Below the source code for FirstRecurringCharacter in java.
package com.raj.programs;
import java.util.Hashtable;
public class FirstRecurringCharacter {
public static String firstRecurring(String inputString) {
Hashtable<String, String> table = new Hashtable<>(inputString.length());
for(char c : inputString.toCharArray()) {
if(table.containsKey(String.valueOf(c))){
System.out.println("First Recurring character is : "+c);
return String.valueOf(c);
}else {
table.put(String.valueOf(c), String.valueOf(c));
}
}
System.out.println("Not found");
return null;
}
public static void main(String[] args) {
FirstRecurringCharacter.firstRecurring("ABCDEFA");
FirstRecurringCharacter.firstRecurring("ABCDEF");
}
}
Below the source code for FirstRecurringCharacter in java.
package com.raj.programs;
import java.util.Hashtable;
public class FirstRecurringCharacter {
public static String firstRecurring(String inputString) {
Hashtable<String, String> table = new Hashtable<>(inputString.length());
for(char c : inputString.toCharArray()) {
if(table.containsKey(String.valueOf(c))){
System.out.println("First Recurring character is : "+c);
return String.valueOf(c);
}else {
table.put(String.valueOf(c), String.valueOf(c));
}
}
System.out.println("Not found");
return null;
}
public static void main(String[] args) {
FirstRecurringCharacter.firstRecurring("ABCDEFA");
FirstRecurringCharacter.firstRecurring("ABCDEF");
}
}
No comments:
Post a Comment