How can I read input from the console using the Scanner class in Java?

前端 未结 15 1945
我寻月下人不归
我寻月下人不归 2020-11-21 06:19

How could I read input from the console using the Scanner class? Something like this:

System.out.println(\"Enter your username: \");
Scanner = i         


        
15条回答
  •  南笙
    南笙 (楼主)
    2020-11-21 06:57

    import java.util.*;
    
    class Ss
    {
        int id, salary;
        String name;
    
       void Ss(int id, int salary, String name)
        {
            this.id = id;
            this.salary = salary;
            this.name = name;
        }
    
        void display()
        {
            System.out.println("The id of employee:" + id);
            System.out.println("The name of employye:" + name);
            System.out.println("The salary of employee:" + salary);
        }
    }
    
    class employee
    {
        public static void main(String args[])
        {
            Scanner sc = new Scanner(System.in);
    
            Ss s = new Ss(sc.nextInt(), sc.nextInt(), sc.nextLine());
            s.display();
        }
    }
    

提交回复
热议问题