import java.util.Scanner;
public class JavaApplication45 {
public static String replaceLetter(String txt, String txt1, String txt2 ){
char one = txt1.charAt(0);
char two = txt2.charAt(0);
String newTxt = "";
for (int i = 0; i < txt.length(); i++){
char c = txt.charAt(i);
if (c == one){
newTxt += two;
}
else{
newTxt += c;
}
}
return newTxt;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter your word:");
String word = scan.nextLine();
System.out.println("Enter the letter you want to replace:");
String txt1 = scan.next();
System.out.println("Enter the replacing letter:");
String txt2 = scan.next();
System.out.println(replaceLetter(word,txt1,txt2));
}
}
I hope this helps!