properties文件里student.stuNo = 01什么意思
时间: 2024-05-29 17:14:31 浏览: 10
这是一个 Java properties 文件中的一行配置,表示一个名为 `student` 的属性(或键),其对应的值为 `01`。可能是用来存储学生的学号信息,可以通过读取此配置文件来获取学号信息,例如在 Java 代码中可以使用 `Properties` 类读取该文件并获取 `student` 属性的值。
相关问题
int stuNo = Integer.parseInt(properties.getProperty("student.stuNo"));什么意思
这行代码是从 Java Properties 对象中获取名为 "student.stuNo" 的属性值,然后将其解析为整数类型并赋值给变量 stuNo。通常情况下,Properties 对象是用来存储配置信息的,所以这行代码的作用是获取名为 "student.stuNo" 的配置项的值,并将其转换为整数类型以便后续使用。如果属性不存在或无法解析为整数,则会抛出 NumberFormatException 异常。
package homework; public class Student { class Student{ private String name; private int stuNo; private String sex; private String grade; private double score; } public static void main(String[] args) { Student stu=new Student(); stu.name="Monkey"; stu.stuNo="000001"; stu.sex="man"; stu.grade="first grade"; stu.score="100.00"; System.out.println("姓名:"+stu.name+"学号:"+stu.stuNo+"性别:"+stu.sex+"班级:"+stu.grade+"成绩:"+stu.score+""); } }输出结果是什么
输出结果是:编译错误,因为在赋值时,stuNo和score应该是int和double类型,而不是String类型。正确的代码应该是:
public class Student{
private String name;
private int stuNo;
private String sex;
private String grade;
private double score;
public static void main(String[] args) {
Student stu=new Student();
stu.name="Monkey";
stu.stuNo=000001;
stu.sex="man";
stu.grade="first grade";
stu.score=100.00;
System.out.println("姓名:" + stu.name + " 学号:" + stu.stuNo + " 性别:" + stu.sex + " 班级:" + stu.grade + " 成绩:" + stu.score);
}
}