java怎么实现学生通过登录页面的学号得到自己的学生信息?

如题所述

<pre t="code" l="java">//已成功运行通过可自己写学号测试
public class test {
public static void main(String args[]) {
String s = "d344";
if(check(s))
System.out.println("学号正确");
else System.out.println("学号错误");
System.out.println("专业为:"+getmajor(s));
}

public static Boolean check(String s) {
Boolean t=true;
String s1=s.substring(0, 7);
String s2=s.substring(8, 11);
try{
Integer i=Integer.parseInt(s1);
Integer j=Integer.parseInt(s2);
}catch(Exception e){
t=false;
}

return t;

}

public static String getmajor(String s) {
return s.substring(5, 7);

}

}
温馨提示:答案为网友推荐,仅供参考