请用java编写程序,将某位学员的个人信息输出到屏幕上。信息包括姓名(字符串常量)、性别(字符常量)、年龄(整型常量)、身高(单位米,小数常量)、婚否(布尔常量)。
时间: 2024-09-08 11:04:02 浏览: 60
字符串string.zip
你可以使用下面的Java代码来创建一个简单的`Person`类,并实例化一个对象来输出学员的个人信息:
```java
public class Person {
private String name;
private char gender;
private int age;
private double height;
private boolean isMarried;
// 构造函数
public Person(String name, char gender, int age, double height, boolean isMarried) {
this.name = name;
this.gender = gender;
this.age = age;
this.height = height;
this.isMarried = isMarried;
}
// 输出个人信息的方法
@Override
public String toString() {
return "Name: " + name + "\nGender: " + gender + "\nAge: " + age + "\nHeight (m): " + height + "\nIs Married: " + (isMarried ? "Yes" : "No");
}
public static void main(String[] args) {
Person student = new Person("张三", 'M', 20, 1.75, true);
System.out.println(student);
}
}
阅读全文