About 1,030,000 results
Open links in new tab
  1. java - Using Scanner to ask for your name - Stack Overflow

    code: import java.util.Scanner; class usersName { public static void main(String[] args) { String usersName; System.out.print("Please enter your name: "); usersName = java.util.Scanner; System.out.println("Hello, " + usersName!

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

    Let’s say you ask the user for their name and print a greeting: Scanner scanner = new Scanner ( System . in ) ; System . out . print ( "Enter your name: " ) ; String name = scanner . next ( ) ; System . out . println ( "Hello, " + name + "!"

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

  4. How do you prompt a user for an input in java - Stack Overflow

    Nov 7, 2014 · Use a scanner, as you said: Scanner in = new Scanner(System.in); Then, prompt the user to enter something in: String userChoice = in.nextLine(); Also, when you compared strings: if(userChoice == "Heads") {... that's bad to do for none-primitive objects. It's best to only use the == to compare values that are ints or enums. If you compare a ...

  5. How to write a java program to accept the full name of a person …

    May 17, 2015 · Here is my code: import java.util.*; class Name{ public static void main(String[] args){ System.out.println("Please enter a Firstname , MiddleName & Lastname separated by spaces"); Scanner sc = new Scanner(System.in); String name = sc.nextLine(); System.out.println(name); String[] arr = name.split(" ",3); System.out.println(arr[0].charAt(0 ...

  6. How to prompt user input in a Java console application

    Discover how to effectively prompt and handle user input in Java console applications. Learn to use the Scanner class to capture various data types and create interactive experiences.

  7. java - Beginner's exercise to ask for first names and surnames - Code

    Class names should be Capitalized ("Testing", "Funcs", ...) Class members and variables should use camel case ("firstName", "inputSn", ...) Also: The method names of class funcs behaves like a "setter", so it should have a name like setNames. In general, try to …

  8. java - The better way to ask for input? - Software Engineering …

    Dec 23, 2014 · Console does offer access to a Reader, which you can use to instantiate a Scanner: Console console = System.console(); String name = console.readLine("Please enter your name: "); Scanner consoleScanner = new Scanner(console.reader()); int age = consoleScanner.nextInt();

  9. Best Ways to Capture User Input in Java (With Examples)

    Feb 14, 2025 · Learn how to capture user input in Java using Scanner, BufferedReader, Console, and DataInputStream. Discover the best method for building interactive Java applications.

  10. User Input · AP Computer Science in Java - codehs.gitbooks.io

    To read the user's input as a string, we usereadLine("String prompt"). This allows us to ask the user for their name, favorite color, or any other text input from the user. Here is an example of how we would ask the user for their favorite color, and then print it: // Ask for the input, and store it in the 'favColor' string.

Refresh