How do I rephrase a user input in java…for example if a user enter ‘I love you’ and I would like to set it up to be rephrased to ‘I hate you’ how can I do that?
import java.util.Scanner;
public class Main {
public static void main(String args) {
Scanner scanner = new Scanner(System.in);
// Prompt the user to enter input
System.out.print("Enter your input: ");
String userInput = scanner.nextLine();
// Rephrase the input
String rephrasedInput = userInput.replace("love", "hate");
// Display the rephrased input
System.out.println("Rephrased input: " + rephrasedInput);
}
}
1 Like