import?java.io.BufferedReader;
創(chuàng)新互聯(lián)公司長期為數(shù)千家客戶提供的網(wǎng)站建設(shè)服務(wù),團隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為浙江企業(yè)提供專業(yè)的網(wǎng)站設(shè)計、成都網(wǎng)站制作,浙江網(wǎng)站改版等技術(shù)服務(wù)。擁有十載豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。
import?java.io.IOException;
import?java.io.InputStreamReader;
public?class?Test222?{
public?static?void?main(String[]?args)?throws?IOException?{
int?i,?j;
String?a;
BufferedReader?str?=?new?BufferedReader(
new?InputStreamReader(System.in));
System.out.println("請輸入學(xué)號:");
a?=?str.readLine();
System.out.println("學(xué)號為:"?+?a);
str?=?new?BufferedReader(new?InputStreamReader(System.in));
System.out.println("請輸入姓名:");
a?=?str.readLine();
System.out.println("姓名為:"?+?a);
}
}
望采納~~
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)?返回一個基本類型的整型,?返回負數(shù)表示:o1?小于o2,
?*?返回0?表示:o1和o2相等,?返回正數(shù)表示:o1大于o2。
?*/
public?int?compare(Student?o1,?Student?o2)?{
//?按照學(xué)生的學(xué)號進行升序排列
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)?返回一個基本類型的整型,?返回負數(shù)表示:o1?小于o2,
?*?返回0?表示:o1和o2相等,?返回正數(shù)表示:o1大于o2。
?*/
public?int?compare(Student?o1,?Student?o2)?{
//?按照學(xué)生的年齡進行升序排列
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;
}
}
import?java.util.Comparator;
public?class?Student?implements?ComparableStudent?{
private?int?no;
private?String?name;
private?String?sex;
private?int?roomNo;
private?double?score;
public?Student(int?no,?String?name,?String?sex,?int?roomNo,?double?score)?{
this.no?=?no;
this.name?=?name;
this.sex?=?sex;
this.roomNo?=?roomNo;
this.score?=?score;
}
public?Student(int?no,?String?name,?String?sex,?double?score)?{
this.no?=?no;
this.name?=?name;
this.sex?=?sex;
this.score?=?score;
}
public?int?getNo()?{
return?no;
}
public?void?setNo(int?no)?{
this.no?=?no;
}
public?String?getName()?{
return?name;
}
public?void?setName(String?name)?{
this.name?=?name;
}
public?String?getSex()?{
return?sex;
}
public?void?setSex(String?sex)?{
this.sex?=?sex;
}
public?int?getRoomNo()?{
return?roomNo;
}
public?void?setRoomNo(int?roomNo)?{
this.roomNo?=?roomNo;
}
public?double?getScore()?{
return?score;
}
public?void?setScore(double?score)?{
this.score?=?score;
}
@Override
public?int?compareTo(Student?o)?{
if?(this.no??o.no)?return?1;
else?if?(this.no??o.no)?return?-1;
else?return?0;
}
@Override
public?String?toString()?{
return?"Student{"?+
"no="?+?no?+
",?name='"?+?name?+?'\''?+
",?sex='"?+?sex?+?'\''?+
",?roomNo="?+?roomNo?+
",?score="?+?score?+
'}';
}
}
//性別比較器類
class?SexComparator?implements?ComparatorStudent?{
@Override
public?int?compare(Student?o1,?Student?o2)?{
if?(o1.getSex().compareTo(o2.getSex())??0)?return?1;
else?if?(o1.getSex().compareTo(o2.getSex())??0)?return?-1;
else?return?0;
}
}
//寢室號比較器類
class?RoomNoComparator?implements?ComparatorStudent?{
@Override
public?int?compare(Student?o1,?Student?o2)?{
if?(o1.getRoomNo()??o2.getRoomNo())?return?1;
else?if?(o1.getRoomNo()??o2.getRoomNo())?return?-1;
else?return?0;
}
}
//入學(xué)成績比較器類
class?ScoreComparator?implements?ComparatorStudent?{
@Override
public?int?compare(Student?o1,?Student?o2)?{
if?(o1.getScore()??o2.getScore())?return?1;
else?if?(o1.getScore()??o2.getScore())?return?-1;
else?return?0;
}
}
import?java.util.ArrayList;
import?java.util.Arrays;
import?java.util.Collections;
import?java.util.List;
public?class?TestStudent?{
public?static?void?main(String[]?args)?{
Student?s1?=?new?Student(1,?"jack",?"boy",?90);
Student?s2?=?new?Student(5,?"jack",?"boy",?90);
Student?s3?=?new?Student(4,?"jack",?"boy",?90);
Student?s4?=?new?Student(2,?"jack",?"boy",?90);
ListStudent?studentList=new?ArrayList();
studentList.add(s1);
studentList.add(s2);
studentList.add(s3);
studentList.add(s4);
Collections.sort(studentList);
System.out.println(Arrays.toString(studentList.toArray()));
}
}
不可以。java是一種面向?qū)ο蟮木幊陶Z言。在java語言中,學(xué)生的學(xué)號只能用sno表示,不能使用其他字母組合進行表示,所以不能用mt表示,java語言具有功能強大和簡單易用兩個特征,具有簡單性、面向?qū)ο?、分布式等特點,可以編寫桌面應(yīng)用程序、Web應(yīng)用程序、分布式系統(tǒng)和嵌入式系統(tǒng)應(yīng)用程序等。
下面是一個java 小程序?qū)崿F(xiàn)的\x0d\x0aimport java.awt.*;//引入包\x0d\x0aimport java.applet.Applet;//引入包\x0d\x0apublic class Output extends Applet//定義類\x0d\x0a{\x0d\x0a //定義變量\x0d\x0a private String name;\x0d\x0a private int num;\x0d\x0a //初始化\x0d\x0a public void init()\x0d\x0a {\x0d\x0a name = getParameter("vname");\x0d\x0a num = Integer.parseInt(getParameter("vnum"));\x0d\x0a }\x0d\x0a //輸出\x0d\x0a public void paint(Graphics g)\x0d\x0a {\x0d\x0a g.drawString ("姓名:"+name+";學(xué)號:"+num,20,30);\x0d\x0a }\x0d\x0a}\x0d\x0a\x0d\x0a相應(yīng)的html文件\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a