在这个类中,我添加方法addstudent(),这里的参数应至少有8个数字,并且第一个数字为零。当我运行程序时,我总是变得虚假。
import java.io.*;
public class Module {
public static final int MAX_STUDENTS = 300;
private String module;
private int id;
private String lec;
private String code;
private int sem;
private String modCode;
private String group;
public Module() {
module = "module";
}
public Module(String modCode) {
this.modCode = modCode;
}
public boolean addStudent(int id) {
String s_id = Integer.toString(id);
int idlength = s_id.length();
char fdigit = s_id.charAt(0);
boolean b1 = fdigit == 0;
if ((idlength >= 8) && (b1)) {
return true;
}
else {
return false;
}
}
}
这是测试类 -
import java.io.*;
public class ModuleTest {
public static void main(String[] args) {
Module Software = new Module("0123456789");
Software.addStudent(012344567);
System.out.println(Software.addStudent(012344567));
}
}