dimanche 31 juillet 2016

In java, I want to enter a string in a scanner but it will only take the string until a space

My example input: Welcome to Java

My output with this code: Welcome

Expected output: Welcome to java

What is wrong with the following code where it accepts multiple characters with spaces?

import java.util.Scanner;
public class Example {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        System.out.print("String: " + s);
    }
}

Aucun commentaire:

Enregistrer un commentaire