// the question is about methodOverloading in java. I am having trouble with this method, i only included this one method as the others are working fine
// i test this code with the string "the cat sat on the mat" "1" "12" "a" "m"
//the method should remove all characters beteen the given characters(exclusive) from the string. this should happen between the first instance of the first character and the last instance of the second character.
// with the string "the cat sat on the mat" this method should print out "the camat"
import java.util.Scanner;
public class methodOverloading
{
public static void main (String [] args)
{
Scanner scan = new Scanner (System.in);
String s = scan.nextLine();
char c1 = scan.next().charAt(0);
char c2 = scan.next().charAt(0);
System.out.println(manipulation(s,c1,c2));//part 5// not working
public static String manipulation(String s, char c1, char c2)
{
int a =0 ,b =0;
for(int i =0; i<s.length(); i++)
{
if(s.charAt(i)==c1);
{
a=i;
System.out.println(i);
break; // for some reason i doesn't get past 0, i have printed out the value stored in i at this point and is 0
}
}
for(int j = s.length()-1; j>=0;j--)
{
if(s.charAt(j)==c2)
{
b = j;
break;
}
}
System.out.println(a); // this also prints out 0, it should print out 6
System.out.println(b);// this prints out 19 which is expected
String s2 = s.substring(a+1,b-1); // this doesnt print out "the camat" it prints out "t mat", if i hard code the print statement to print out a substring of s from (6 to 19) it prints out "the camat" as expected
s =s.replace(s2, "");
return s;
}
}