-2

I want to take values from user for this program, that is value for Name, roll, salary directly from an user.

How to do that?

 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);
    }
}

Can anyone please help?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

1

You can read in a line from the command line using a 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();
Max
  • 15,157
  • 17
  • 82
  • 127