不可以。java是一種面向?qū)ο蟮木幊陶Z言。在java語言中,學(xué)生的學(xué)號(hào)只能用sno表示,不能使用其他字母組合進(jìn)行表示,所以不能用mt表示,java語言具有功能強(qiáng)大和簡單易用兩個(gè)特征,具有簡單性、面向?qū)ο蟆⒎植际降忍攸c(diǎn),可以編寫桌面應(yīng)用程序、Web應(yīng)用程序、分布式系統(tǒng)和嵌入式系統(tǒng)應(yīng)用程序等。

成都創(chuàng)新互聯(lián)公司服務(wù)項(xiàng)目包括廣靈網(wǎng)站建設(shè)、廣靈網(wǎng)站制作、廣靈網(wǎng)頁制作以及廣靈網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,廣靈網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到廣靈省份的部分城市,未來相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
class?Student?{
private?String?name;
private?int?stuId;
private?float?score;
public?String?getName()?{
return?name;
}
public?void?setName(String?name)?{
this.name?=?name;
}
public?int?getStuId()?{
return?stuId;
}
public?void?setStuId(int?stuId)?{
this.stuId?=?stuId;
}
public?float?getScore()?{
return?score;
}
public?void?setScore(float?score)?{
this.score?=?score;
}
public?void?showInfo()?{
System.out.println("Student?[name="?+?name?+?",?stuId="?+?stuId?+?",?score="?+?score?+?"]");
}
}
import?java.util.ArrayList;
import?java.util.Collections;
import?java.util.Comparator;
import?java.util.List;
public?class?Sort?{
public?static?void?main(String[]?args)?{
Student?p1?=?new?Student(1001,?"小明",?20);
Student?p2?=?new?Student(1002,?"小紅",?21);
Student?p3?=?new?Student(1003,?"小黑",?19);
ListStudent?list?=?new?ArrayListStudent();
list.add(p1);
list.add(p2);
list.add(p3);
Collections.sort(list,?new?ComparatorStudent()?{
/*
?*?int?compare(Student?o1,?Student?o2)?返回一個(gè)基本類型的整型,?返回負(fù)數(shù)表示:o1?小于o2,
?*?返回0?表示:o1和o2相等,?返回正數(shù)表示:o1大于o2。
?*/
public?int?compare(Student?o1,?Student?o2)?{
//?按照學(xué)生的學(xué)號(hào)進(jìn)行升序排列
if?(o1.getId()??o2.getId())?{
return?1;
}
if?(o1.getId()?==?o2.getId())?{
return?0;
}
return?-1;
}
});
write(list);
System.out.println("---------------------");
Collections.sort(list,?new?ComparatorStudent()?{
/*
?*?int?compare(Student?o1,?Student?o2)?返回一個(gè)基本類型的整型,?返回負(fù)數(shù)表示:o1?小于o2,
?*?返回0?表示:o1和o2相等,?返回正數(shù)表示:o1大于o2。
?*/
public?int?compare(Student?o1,?Student?o2)?{
//?按照學(xué)生的年齡進(jìn)行升序排列
if?(o1.getAge()??o2.getAge())?{
return?1;
}
if?(o1.getAge()?==?o2.getAge())?{
return?0;
}
return?-1;
}
});
write(list);
}
public?static?void?write(ListStudent?list)?{
for?(Student?s?:?list)?{
System.out.println(s.getId()?+?"\t"?+?s.getName()?+?"\t"
+?s.getAge());
}
}
}
public?class?Student?{
private?int?id?;
private?String?name;
private?int?age;
//構(gòu)造方法
public?Student(int?id,String?name,int?age){
this.id?=?id;
this.name?=?name;
this.age?=?age;
}
public?int?getId()?{
return?id;
}
public?void?setId(int?id)?{
this.id?=?id;
}
public?String?getName()?{
return?name;
}
public?void?setName(String?name)?{
this.name?=?name;
}
public?int?getAge()?{
return?age;
}
public?void?setAge(int?age)?{
this.age?=?age;
}
}
這個(gè)很簡單呀,要自己試著去寫。
public class Students {
private String ID; //學(xué)號(hào)
private String classId; //班級(jí)
private String name; //姓名
private int age; //年齡
public Students(String ID,String classId,String name,int age){//構(gòu)造函數(shù)
this.ID=ID;
this.classId=classId;
this.name=name;
this.age= age;
}
public String getiID() {//獲得學(xué)號(hào)
return this.ID;
}
public String getClassId() {//獲得班級(jí)
return this.classId;
}
public String getName() {//獲得姓名
return this.name;
}
public int getAge() {//獲得年齡
return this.age;
}
public void setAge(int age){//修改年齡
this.age=age;
}
public static void main(String args[]){
Students st=new Students("111101","一班","張三","20");
System.out.println(st.getAge());
st.setAge(30);
System.out.println(st.getAge());
}
}
如果在完整一些,可以在加一個(gè)toString()函數(shù),用來返回要輸出的字符串。
小眾的treeset + 策略模式 幫你實(shí)現(xiàn)一個(gè).
import?java.util.TreeSet;
public?class?Test?{
/**
?*?測試,TreeSet?1去重?2比較器排序?3比較器中小眾的擴(kuò)展三目表達(dá)式應(yīng)用
?*?
?*?@param?args
?*/
public?static?void?main(String[]?args)?{
TreeSetStudent?set?=?new?TreeSetStudent(new?CompareUtils());
set.add(new?Student(1,?"remind"));
set.add(new?Student(3,?"lucy"));
set.add(new?Student(2,?"lird"));
set.add(new?Student(3,?"houty"));
set.add(new?Student(4,?"tina"));
set.add(new?Student(7,?"houty"));
for?(Student?stu?:?set)?{
System.out.println(stu);
}
}
}
/**
*?pojo類
*?
*?@author?remind
*?
*/
public?class?Student?{
private?int?id;
private?String?name;
public?int?getId()?{
return?id;
}
public?void?setId(int?id)?{
this.id?=?id;
}
public?String?getName()?{
return?name;
}
public?void?setName(String?name)?{
this.name?=?name;
}
@Override
public?int?hashCode()?{
final?int?prime?=?31;
int?result?=?1;
result?=?prime?*?result?+?id;
result?=?prime?*?result?+?((name?==?null)???0?:?name.hashCode());
return?result;
}
@Override
public?boolean?equals(Object?obj)?{
if?(this?==?obj)
return?true;
if?(obj?==?null)
return?false;
if?(getClass()?!=?obj.getClass())
return?false;
Student?other?=?(Student)?obj;
if?(id?!=?other.id)
return?false;
if?(name?==?null)?{
if?(other.name?!=?null)
return?false;
}?else?if?(!name.equals(other.name))
return?false;
return?true;
}
public?Student()?{
super();
//?TODO?Auto-generated?constructor?stub
}
public?Student(int?id,?String?name)?{
super();
this.id?=?id;
this.name?=?name;
}
@Override
public?String?toString()?{
return?"Student?[id="?+?id?+?",?name="?+?name?+?"]";
}
}
import?java.util.Comparator;
/**
*?比較器
*?
*?@author?remind
*?
*/
public?class?CompareUtils?implements?ComparatorStudent?{
@Override
public?int?compare(Student?o1,?Student?o2)?{
return?(o1.getId()??o2.getId())???1?:?(o1.getId()?==?o2.getId())???0?:?-1;
}
}
標(biāo)題名稱:Java的學(xué)號(hào)代碼是什么 java里輸出學(xué)號(hào)的程序是什么
網(wǎng)址分享:http://www.chinadenli.net/article38/hpigsp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營銷型網(wǎng)站建設(shè)、移動(dòng)網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)、手機(jī)網(wǎng)站建設(shè)、電子商務(wù)、App設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)