键盘输入

时间:2016-03-14 16:44:10

标签: java user-input

我想从用户那里获取此计划的值,该值是直接来自用户的Namerollsalary的值。

怎么做?

 public class MethodOverloadingPractice {

    public void display(String name){
        System.out.println("Name is "+name);
    }

    public void display(String name, int roll){
        System.out.println("Name is " + name + "Roll is " + roll);
    }

    public void display(String name, int roll, double salary){
        System.out.println("Name is " + name + "Roll is " + roll + "Salary is " + salary);
    }      
}

class MOP{
    public static void main(String[] args){
    MethodOverloadingPractice obj = new MethodOverloadingPractice();
    obj.display("Jannatin");
    obj.display("Jannatin", 101);
    obj.display("Jannatin", 101, 150);
    }
}

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

您可以使用Scanner从命令行读取一行。

Scanner scanner = new Scanner(System.in);
scanner.useDelimiter(System.getProperty("line.separator"));
String name = scanner.next();
String roll = scanner.next();
String salary = scanner.next();
scanner.close();