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

    Java User Input. The Scanner class is used to get user input, and it is found in the java.util package. 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:

  2. java - Declaring a variable via Scanner? - Stack Overflow

    Nov 12, 2013 · public void timerTwo() { System.out.println("Please Enter Run time in minutes as an integer: "); Scanner scan = new Scanner(System.in); n = scan.nextInt(); // <-- read n here for first time timeTimerTimer.scheduleAtFixedRate(new TimerTask() {...}, timeTimerDelay, timeTimerPeriod * n); }

  3. java.util.scanner - How do I assign user input to a variable in Java ...

    Jun 12, 2014 · Try this sexy code on for size: Scanner scan = new Scanner(System.in); //User input of length and width System.out.print("Please input the width of the property in feet:"); width = scan.nextDouble(); System.out.print("Please input the length of the property in feet:"); length = scan.nextDouble();

  4. Is it possible to declare a scanner variable inside a method in Java

    Jul 7, 2017 · In any case, you shouldn't be creating a Scanner in every method. Create a Scanner once and pass it as a parameter to methods that need it. yes i fixed the missing curly brace before program execution. So in these situations i should pass a Scanner object to the method.

  5. Beginner's Guide To Java Scanner (With Code Examples)

    What is the Java Scanner class? How to set up and import Scanner; How to use Scanner. How to read text input with next() and nextLine() How to read numbers with nextInt() and nextDouble() How to read Boolean input; Best practices for using Scanner; Common mistakes and how to fix them; Time to give a Scanner a try with your own code!

  6. just for java

    once we import the Scanner class, then we can create a Scanner variable (btw: make sure to capitalize the S in Scanner). this means that we can now get user input from the console (btw: the console is where you see anything printed out, and that is …

  7. 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.

  8. Java Input - Using Java Scanner - Java Made Easy!

    First, we need to create the Scanner variable: Remember to right click on the main page, select source, and then select organize imports. Next you need to create an int variable to store the first input.

  9. java - Setting a scanner as a global variable - Stack Overflow

    Jan 13, 2014 · If you're not already familiar with line-by-line debugging in whatever IDE you're using, this would be a good time to try. You can step through your code to determine why an empty string is being passed into getInitial().

  10. Java Scanner class with examples - BeginnersBook

    Sep 11, 2022 · In this tutorial, you will learn Java Scanner class and how to use it in java programs to get the user input. This is one of the important classes as it provides you various methods to capture different types of user entered data.

Refresh