I can never find a way to keep away from this damn site.
I need to crowd source real quick because its late and no one can help me. Google and my textbooks have failed me as well.
I'm writing a toy program in which I must ask the user for an input, and I output that input by replacing all the spaces with an underscore.
Wrote something that looks like this:
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Input filename");
String filename = in.next();
String output = filename.replaceAll(" ", "_");
System.out.println(output);
}
If the filename string wasn't a scanner input, this would actually work. The result for this particular program, however, only prints out the first word of the input and throws out the rest of it.
If the replace method tries to replace a letter in the first word, then it works.
If I don't use the replace method, the output comes out fully like it should.
What am I doing wrong? Would be fantastic if someone who knows how to program could lend a hand... soon.