求高手编写一个满足下列要求的程序:JAVA的

编写一个满足下列要求的程序:1)为学生创建一个类(类名:Student),这个类包含的属性有:学生姓名(字符串)、ID(整数)和状态(整数)。状态表示学生的年级:1表示新... 编写一个满足下列要求的程序:
1)为学生创建一个类(类名:Student),这个类包含的属性有:学生姓名(字符串)、ID(整数)和状态(整数)。状态表示学生的年级:1表示新生,2表示二年级,3表示三年级,4表示四年级。
2)创建20个学生对象,姓名为Name1,Name2……直到Name20。他们的ID和年级都随机指定。
3)找出所有三年级的学生并输出他们的姓名和ID。
三、设定五个字符串{study, learnED, IDED, ED, research },并只打印那些以字母“ED”结尾的串。
四、设定一个有大小写字母的字符串”I love JAVA and C”,先将字符串中的大写字符输出,再将字符串中的小写字符输出。
展开
 我来答
flyingFish211
2010-12-26 · TA获得超过2.1万个赞
知道大有可为答主
回答量:1.5万
采纳率:50%
帮助的人:1.1亿
展开全部
第一 二个:
public class Student {

private String name;
private int id;
private int state;

public Student(String name, int id, int state){
this.name = name;
this.id = id;
this.state = state;
}

public static void main(String[] args) {

Student[] students = new Student[20];
initStudentsArrary(students);

for(int i = 0, len = students.length; i < len; i++){
if(students[i].getState() == 3){
System.out.println(students[i].toString());
}
}

}

private static void initStudentsArrary(Student[] students) {
students[0] = new Student("Name1", 11, 1);
students[1] = new Student("Name2", 22, 2);
students[2] = new Student("Name3", 33, 3);
students[3] = new Student("Name4", 44, 4);
students[4] = new Student("Name5", 55, 1);
students[5] = new Student("Name6", 61, 2);
students[6] = new Student("Name7", 72, 3);
students[7] = new Student("Name8", 83, 3);
students[8] = new Student("Name9", 91, 2);
students[9] = new Student("Name10", 8, 4);
students[10] = new Student("Name11", 7, 4);
students[11] = new Student("Name12", 6, 3);
students[12] = new Student("Name13", 3, 2);
students[13] = new Student("Name14", 2, 1);
students[14] = new Student("Name15", 1, 2);
students[15] = new Student("Name16", 4, 3);
students[16] = new Student("Name17", 9, 1);
students[17] = new Student("Name18", 10, 4);
students[18] = new Student("Name19", 12, 2);
students[19] = new Student("Name20", 14, 3);
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public int getState() {
return state;
}

public void setState(int state) {
this.state = state;
}

public String toString(){
return "[name, id, state]: " + name +", "+ id + ", " + state;
}
}

---------------------
[name, id, state]: Name3, 33, 3
[name, id, state]: Name7, 72, 3
[name, id, state]: Name8, 83, 3
[name, id, state]: Name12, 6, 3
[name, id, state]: Name16, 4, 3
[name, id, state]: Name20, 14, 3

第三个:
public class Second {

public static void main(String[] args) {

String[] strs = { "study", "learnED", "IDED", "ED", "research" };

for (String str : strs) {
if (str.endsWith("ED")) {
System.out.println(str);
}
}

}

}
-------------
learnED
IDED
ED

第四个:
public class Third {

public static void main(String[] args) {

String str = "I love JAVA and C";

StringBuffer sbUpperCase = new StringBuffer();
StringBuffer sbLowerCase = new StringBuffer();

for (int i = 0, len = str.length(); i < len; i++) {
char item = str.charAt(i);

if (item >= 'A' && item <= 'Z') {
sbUpperCase.append(item);
} else if (item >= 'a' && item <= 'z') {
sbLowerCase.append(item);
}
}

System.out.println(sbUpperCase.toString());
System.out.println(sbLowerCase.toString());

}

}
-------------------
package zhidao;

public class Third {

public static void main(String[] args) {

String str = "I love JAVA and C";

StringBuffer sbUpperCase = new StringBuffer();
StringBuffer sbLowerCase = new StringBuffer();

for (int i = 0, len = str.length(); i < len; i++) {
char item = str.charAt(i);

if (item >= 'A' && item <= 'Z') {
sbUpperCase.append(item);
} else if (item >= 'a' && item <= 'z') {
sbLowerCase.append(item);
}
}

System.out.println("字符串" + str + "中大写字母:" + sbUpperCase.toString());
System.out.println("字符串" + str + "中小写字母: " + sbLowerCase.toString());

}

}
------------
字符串I love JAVA and C中大写字母:IJAVAC
字符串I love JAVA and C中小写字母: loveand
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式