i'm trying to learn some stuff and i'm having trouble. my code looks like this: import java.util.Scanner; public class MessingAround { public static void main(String[] args) { String s; Scanner a = new Scanner(System.in); System.out.println("Enter a string."); s = a.next(); System.out.print("You said: " + s); } } it prints only the first word of any string i enter. ex) Enter a string. bow ties are cool You said: bow help?
i changed s = a.next(); to s = a.nextLine(); i think that's right because it works now
yes, that was the error.
A scanner is going to break a string into tokens. Calling a.next() once will get one token. You'd either need to loop through the tokens, print it and add a separator character, or do what you did which kind of makes the scanner unneeded.
Join our real-time social learning platform and learn together with your friends!