编写一个简单的Java Application程序,向系统输出设备输出自己的基本信息:姓名、学号、专业、特长爱好等信息、
时间: 2024-09-26 15:05:36 浏览: 35
当然可以。在Java中,你可以创建一个名为`Student`的简单类来代表一个学生,然后实例化这个类并打印其属性。下面是一个示例:
```java
public class Student {
private String name;
private int studentNumber;
private String major;
private String hobby;
// 构造函数
public Student(String name, int studentNumber, String major, String hobby) {
this.name = name;
this.studentNumber = studentNumber;
this.major = major;
this.hobby = hobby;
}
// 获取和设置属性的方法
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public int getStudentNumber() { return studentNumber; }
public void setStudentNumber(int studentNumber) { this.studentNumber = studentNumber; }
public String getMajor() { return major; }
public void setMajor(String major) { this.major = major; }
public String getHobby() { return hobby; }
public void setHobby(String hobby) { this.hobby = hobby; }
@Override
public String toString() {
return "Name: " + name + ", Student Number: " + studentNumber +
", Major: " + major + ", Hobby: " + hobby;
}
}
// 程序主入口
public class Main {
public static void main(String[] args) {
Student student = new Student("张三", 20200101, "计算机科学", "编程");
System.out.println(student);
}
}
```
当你运行这个`Main`类的时候,它会输出类似这样的信息:
```
Name: 张三, Student Number: 20200101, Major: 计算机科学, Hobby: 编程
```
阅读全文