About 13,600,000 results
Open links in new tab
  1. Java User Input (Scanner class) - W3Schools

    To use the Scanner class, create an object of the class and use any of the available methods found in the Scanner class documentation. In our example, we will use the nextLine() method, which is used to read Strings: If you don't know what a …

  2. Java Scanner String input - Stack Overflow

    Mar 22, 2012 · import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int i = scan.nextInt(); Double d = scan.nextDouble(); String f = scan.nextLine(); String s = scan.nextLine(); // Write your code here.

  3. Scanner toString () method in Java with Examples

    Oct 11, 2018 · The toString() method of StringWriter Class in Java is used to get the String representation of this StringWriter instance. This method does not accept any parameter and returns the required String value.

  4. How to read strings from a Scanner in a Java console application?

    Jul 17, 2013 · What you can do is use delimeter as new line. Till you press enter key you will be able to read it as string. Scanner sc = new Scanner(System.in); sc.useDelimiter(System.getProperty("line.separator")); Hope this helps.

  5. java - Parsing string using the Scanner class - Stack Overflow

    Aug 20, 2012 · Try using String.split(" "), to split around the spaces. You'll get an array, and if the first character is blank, the first String in the array will be an empty string: String strs[] = " 1 ON OFF".split(" "); With this example you'll get this array: ["", "1", "ON", "OFF"].

  6. Java User Input – Scanner Class - GeeksforGeeks

    Apr 22, 2025 · Import the Scanner class using import java.util.Scanner;; Create the Scanner object and connect Scanner with System.in by passing it as an argument i.e., Scanner sc = new Scanner(System.in);; When we want to ask the user for input, first print a prompt message so they know what to enter. Then use one of Scanner’s handy methods to read the response:

  7. Java Scanner String input example - TheServerSide

    Jul 23, 2022 · To take String input from the user with Java’s Scanner class, just follow these steps. Import java.util.*; to make Java’s Scanner class available; Use the new keyword to create an instance of the Scanner class; Pass the static System.in object to the Scanner’s Java constructor; Use Scanner’s next() method to take input one String at a time

  8. Java Scanner Class Example Tutorial - Java Guides

    The Java Scanner class is widely used to parse text for strings and primitive types using a regular expression. It is the simplest way to get input in Java. With the help of Scanner in Java, we can get input from the user in primitive types as well as strings such as int, long, double, byte, float, short, strings, etc.

  9. How to Take String Input In Java using Scanner Class - Know …

    In this post, we will see how to take string input in java using the scanner class. See more:- String Programs In Java. There are two different options:- read one word or read one line. In the Scanner class, we have the next () method which reads one word at a time and nextLine () method which reads one line at a time. Read one word at a time.

  10. Java Scanner Class – Definition And Example - PW Skills

    Apr 2, 2025 · The java.util package in Java has a class called Scanner. This class helps to connect the program with the input stream, allowing it to read and understand different types of data like strings, characters, integers, and doubles.

Refresh