您好如何使用eclipse进行用户输入。就像命令提示符一样,我们
C:/ java javaApp(这里的参数)。如何使eclipse从用户那里获取输入。?
答案 0 :(得分:9)
运行 - >运行配置 - >参数(它是右边的第二个标签) - >程序参数
答案 1 :(得分:2)
在程序中添加此行以接受来自控制台的用户输入:
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
然后在要从Runtime接受输入的任何变量旁边添加in.readLine()。可以说,您希望将count变量初始化为值1,然后,它应该写为
int count = in.readLine();
运行程序
答案 2 :(得分:0)
以下是在Eclips中获取用户输入的一种方法。
import java.util.Scanner; // enter the before the start of any class
// declare the class here
// this is an example of how to use the Scanner in a method
Public static void Username();{
Scanner Input = new scanner (System.in);
String username// declaring the username variable
Scanner un = new Scanner(System.in); // un is just a random variable you can choose any other variable name if you want
System.out.println("Enter Your Username");
username = un.next();
System.out.println("The username you entered is : " + username);}
但是如果你想在这里采用整数或双数作为输入,你将如何做。 我将给出一个int输入的例子,你只需要用double替换int。
import java.util.Scanner;
// Declare the class here
// this is an example of how to use the Scanner in a method for an integer input by user
Public static void booksRead();{
Scanner Input = new scanner (System.in);
int books // declaring the books variable
Scanner br = new Scanner(System.in); // br is just a random variable you can choose any other variable name if you want
System.out.println("Enter how many books have you read: ");
books = br.next();
System.out.println("The number of books you have read is : " + books);}
答案 3 :(得分:0)
这将打印用户输入的数字:
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner reader = new Scanner(System.in); // Reading from System.in
System.out.println("Enter a number: ");
int n = reader.nextInt(); // Scans the next token of the input as an int.
//once finished
System.out.println(n);
reader.close();
}