debghosal92
BAN USERget all values from web table and store them to custom class Product class with mentioned info as variables. then match each object with db query result.
- debghosal92 August 06, 2022public class FindDistance {
public static void findCharDistance(String str, char a, char b) {
if(str == null ||
!str.contains(Character.toString(a)) ||
!str.contains(Character.toString(b)) ||
str.isBlank()) {
System.out.println("-1");
}else if(a != b){
System.out.println(Math.abs(str.indexOf(a) - str.indexOf(b)));
}else {
System.out.println(Math.abs(str.indexOf(a) - str.lastIndexOf(b)));
}
}
}
test data :
FindDistance.findCharDistance(null, 'a', 'b');
FindDistance.findCharDistance(" ", 'a', 'b');
FindDistance.findCharDistance("Ajay is here", 'A', 'z');
FindDistance.findCharDistance("Ajay is here", 'z', 'h');
FindDistance.findCharDistance("Ajay is here", 'A', 'h');
FindDistance.findCharDistance("Ajay is here", 'z', 'y');
FindDistance.findCharDistance("Ajay is here", 'A', 'a');
FindDistance.findCharDistance("Ajay is here", 'A', 'A');
FindDistance.findCharDistance("Ajay is here", 'e', 'e');
- debghosal92 August 07, 2022