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

    import java.util.Scanner; class Main { public static void main(String[] args) { Scanner myObj = new Scanner(System.in); System.out.println("Enter name, age and salary:"); // String input String name = myObj.nextLine(); // Numerical input int age = myObj.nextInt(); double salary = myObj.nextDouble(); // Output input by user System.out.println ...

  2. java - print string by using Scanner class - Stack Overflow

    Aug 20, 2016 · printing only "Welcome" string through scanner class. 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 s = scan.nextLine(); scan.close(); // Write your code here.

  3. java - making the user input a name for the class/scanner to store ...

    Aug 12, 2015 · Scanner scanner1 = new Scanner(System.in); System.out.println("Please enter your name: "); String characterName = scanner1.nextLine(); System.out.println("Hello, " + characterName()); This would ask for the person's name, then say hello to them directly after.

  4. java.util.scanner - How can I read input from the console using

    To retrieve a username I would probably use sc.nextLine(). You could also use next(String pattern) if you want more control over the input, or just validate the username variable. You'll find more information on their implementation in the API Documentation for java.util.Scanner.

  5. Scanner Class in Java - GeeksforGeeks

    Apr 11, 2025 · In Java, the Scanner class is present in the java.util package is used to obtain input for primitive types like int, double, etc., and strings. We can use this class to read input from a user or a file. In this article, we cover how to take …

  6. Java Scanner (With Examples) - Programiz

    The Scanner class of the java.util package is used to read input data from different sources like input streams, users, files, etc. In this tutorial, we will learn about the Java Scanner and its methods with the help of examples.

  7. Java Scanner - Baeldung

    Jan 5, 2024 · We learned how to read input from a file, console, or String using Scanner. We also learned how to find and skip a pattern using Scanner and how to change the Scanner delimiter. Finally, we explained how to handle the NoSuchElementException exception.

  8. Scanner Class in Java (With Examples) - FavTutor

    Oct 25, 2023 · System.out.println("Hello, " + name + "!"); In the above example, we prompt the user to enter their name using System.out.print (). Then, we use scanner.nextLine () to read the input provided by the user and store it in the name variable. Finally, we print a greeting message using the entered name.

  9. Java User Input – Scanner Class - GeeksforGeeks

    Apr 22, 2025 · Follow these steps to take user input using Scanner class: 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: Example: Let us go through a simple example where we get two numbers from the user and add them together:

  10. How To Use Java Scanner Class - Complete Guide With Examples

    Oct 6, 2021 · We have covered all the details about the Java’s Scanner class, including how to import the Scanner class, how to create an object, and how to use the functions with various examples. Java Scanner constructor and Java delimiters are also covered.

  11. Some results have been removed
Refresh