I am currently beginning to learn Java code. One of the problems is to replace all tabs with * and all * with tabs. It was suggested that I first replace all tabs with the newline characters (\n). After that I could then replace * with tabs and tabs with *. I created a code I thought would work but after running it, I discovered it wasn't running properly. Can anyone help me fix the issue?
Scanner in = new Scanner(System.in);
String s = in.nextLine();
s.replaceAll("\t", "\n");
s.replaceAll("\\*", "\t");
s.replaceAll("\n", "\\*");
System.out.println(s);
I have a feeling I am using the print statement incorrectly or maybe I am just setting this entire thing up wrong.
Example user input: **HelloThere* _ _ _ Bye*
Example output: _ _ HelloThere _ ***Bye _
The '_' are representing tabs.