Removing duplicates from a string in Java:
public class LivingBeing {
public static void main(String[] args) {
String input = "ABCA";
String output = "";
for(int index=0; index < input.length(); index++){
System.out.println("Fiste Value is:" + index % input.length());
System.out.println("Second Value is:" + (index+1) % input.length());
System.out.println("Length:" + input.length());
if(input.charAt(index % input.length()) != input.charAt((index+1)% input.length())){
output+=input.charAt(index);
System.out.println("Inner:"+ output);
}
System.out.println("Mid:"+ output);
}
System.out.println("Outside:"+ output);
}
}
public class LivingBeing {
public static void main(String[] args) {
String input = "ABCA";
String output = "";
for(int index=0; index < input.length(); index++){
System.out.println("Fiste Value is:" + index % input.length());
System.out.println("Second Value is:" + (index+1) % input.length());
System.out.println("Length:" + input.length());
if(input.charAt(index % input.length()) != input.charAt((index+1)% input.length())){
output+=input.charAt(index);
System.out.println("Inner:"+ output);
}
System.out.println("Mid:"+ output);
}
System.out.println("Outside:"+ output);
}
}
No comments:
Post a Comment