Get user input String in Java

In Java, the user can provide the string by using java.util.Scanner package which has Scanner class.

Following is the code:


Here sc.next() is used.

If se.next() is used, then only the String before space is taken up.

But if we use sc.nextLine() then,





We get the entire string.

No comments:

Post a Comment