ServiceNow Interview Question

find out distance between two characters in a string

Interview Answer

Anonymous

Dec 21, 2019

String s="sreekumar"; Scanner sc=new Scanner(system.in); char c1=sc.next().charAt(0); char c2=sc.next().charAt(0); System.out.println("Distance between char's "+ (s.indexOf(c2)-s.indexOf(c1)));