約 10,600 件の結果
リンクを新しいタブで開く
  1. The Scanner class in Java is used to get user input and is found in the java.util package. It can read input from various sources like input streams, files, and strings.

    Example

    import java.util.Scanner;

    public class Main {
    public static void main(String[] args) {
    Scanner myObj = new Scanner(System.in); // Create a Scanner object
    System.out.println("Enter username");

    String userName = myObj.nextLine(); // Read user input
    System.out.println("Username is: " + userName); // Output user input

    myObj.close(); // Close the scanner
    }
    }
    コピーしました。

    Methods to Read Different Data Types

    Reading an Integer

    import java.util.Scanner;

    public class Main {
    public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.println("Enter an integer:");

    int data = input.nextInt(); // Reads an int value
    System.out.println("Using nextInt(): " + data);

    input.close();
    }
    }
    コピーしました。

    Reading a Double

    フィードバック
    ありがとうございました!詳細をお聞かせください
  2. How to Take Input From User in Java? - GeeksforGeeks

    2024年12月6日 · This article explains how to take input in Java using the BufferedReader and Scanner classes. It compares both methods and their usage …

  3. How to Take Input as String With Spaces in Java Using Scanner?

    Taking and parsing user input is a common task in our daily Java programming, and handling input that includes spaces can sometimes be tricky. In this tutorial, we’ll explore using the Scannerclass to take input as a string with spaces in Java.
    baeldung.com でさらに表示
    • レビュー数: 2
    • 公開日: 2023年5月24日
  4. How to Continuously Accept User Input in Java Using Scanner?

    Learn how to use Java's Scanner class to continuously accept user input through loops, with code examples and common pitfalls.

  5. Java Scanner Class Example Tutorial

    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, …

  6. Java User Input - Multiple Ways [Easy Examples]

    2022年9月7日 · In java programming language, we have three different kinds of methods through which we can take java user input including Scanner class, …

  7. Reading input - Java Programming

    Below is an example of a program which asks for user input, reads the string entered by the user, and then prints it.

  8. Java Basic Input and Output - Programiz

    In this tutorial, you will learn simple ways to display output to users and take input from users in Java. We will use the print () method to display output and the Scanner class to take input.

  9. How to Take input from user in Java - Programming Cube

    Let’s get started by talking about the basics of taking input from the user in Java. The most common way to do this is through the use of the Scanner class, which is …

  10. How to Take Input in Java? (With examples) - Scaler Topics

    2022年2月10日 · If you're wondering how to take input in java from user, three classes designed for this: BufferedReader, Scanner, and Console. Among these, …

  11. 他の人も質問しています
    読み込んでいます
    回答を読み込めません