java input()
时间: 2023-07-20 18:37:30 浏览: 77
java input
In Java, `input()` is not a built-in function or method. However, there are several ways to receive input from the user in Java.
One common way is to use the `Scanner` class, which is part of the `java.util` package. Here's an example of how to use `Scanner` to receive input from the user:
```java
import java.util.Scanner;
public class Example {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = scanner.nextInt();
System.out.println("You entered: " + num);
scanner.close();
}
}
```
In this example, we create a `Scanner` object and use it to read input from the console using `nextInt()` method. We then print the input back to the console.
There are also other ways to receive input in Java, such as using `BufferedReader` or `JOptionPane`.
阅读全文