学生类,输入和输出学生的姓名、年龄和学号

import java.util.Scanner;

class Student{

    String name;
    int age;
    String no;
    public String getName(){
        return name;
    }
    public int getAge(){
        return age;
    }
    public String getNo(){
        return no;
    }
    Student(String name1,int age1,String no1){
        name=name1;
        age=age1;
        no=no1;
    }


}

public class Main{
    public static void main(String[] args){
        Scanner sca = new Scanner(System.in);
        Student stu = new Student(sca.next(),sca.nextInt(),sca.next());
        System.out.println("Name:"+stu.getName()+" Age:"+stu.getAge()+" No:"+stu.getNo());
    }

}
0

Leave a Reply

Your email address will not be published.