当前位置: 首页 > wzjs >正文

手机电脑同步wordpress厦门网站综合优化贵吗

手机电脑同步wordpress,厦门网站综合优化贵吗,八亿wap建站,给小公司做网站赚钱吗对象数组练习(增删改查) 定义了一个长度为3的数组,数组存储1~3名学生对象作为初始数据,学生对象的学号,姓名各不相同 学生的属性:学号,姓名,年龄。 要求1.再次添加一个学生对象&a…

对象数组练习(增删改查)

定义了一个长度为3的数组,数组存储1~3名学生对象作为初始数据,学生对象的学号,姓名各不相同

学生的属性:学号,姓名,年龄。

要求1.再次添加一个学生对象,并在添加的时候进行学号的唯一性判断。

要求2.添加完毕之后,遍历所有学生信息。

要求3:通过id删除学生信息

​ 如果存在,则删除,如果不存在,则提示删除失败。

要求4.删除完毕之后,遍历所有学生信息。

要求5.查询数组id为“heima002"的学生,如果存在,则将他的年龄+1岁

先建立一个Javabean类

package heima.Test07;public class Student {private int ID;private String name;private int age;public Student() {}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;}
}

要求1.再次添加一个学生对象,并在添加的时候进行学号的唯一性判断。

要求2.添加完毕之后,遍历所有学生信息。

package heima.Test07;public class StudentTest {public static void main(String[] args) {//1.创建数组来存储学生对象Student[] arr = new Student[3];Student s1 = new Student(001, "liuneng", 18);Student s2 = new Student(002, "zhaoliu", 17);Student s3 = new Student(003, "li", 19);//2.把学生放进数组里面arr[0] = s1;arr[1] = s2;arr[2] = s3;//要求1.再次添加一个对象,并在添加的时候进行学号的唯一性判断;Student s4 = new Student(002, "zhao", 16);Boolean flag = contians(arr, s4.getID());if (flag) {//1.当前ID已存在,不用添加System.out.println("当前Id已存在");} else {//当前ID不存在 查询数组是否存满int count = getcount(arr);if(count== arr.length){//当前数组已经存满Student[] newarr = newarr(arr);newarr[count] = s4;printarr(newarr);//遍历数组}else{arr[count] = s4;printarr(arr);}}}public static Boolean contians (Student[]arr,int ID){//比较是否重复for (int i = 0; i < arr.length; i++) {Student s = arr[i];int age = s.getID();if ( age!= 0) {if(age==ID){return true;}}}return false;}public  static  int  getcount(Student[] arr) {//判断已经存了几个对象int count = 0;for (int i = 0; i < arr.length; i++) {if (arr[i] != null) {count++;}}return count;}public  static  Student[]  newarr(Student[] arr) {//创建新数组Student[] newarr = new Student[arr.length+1];for (int i = 0; i < arr.length; i++) {newarr[i]=arr[i];}return newarr;}public static void printarr(Student[] arr){//遍历数组for (int i = 0; i < arr.length; i++) {if (arr[i] != null) {System.out.println(arr[i].getID() + " " + arr[i].getName() + " " + arr[i].getAge());}}}}

要求3:通过id删除学生信息

​ 如果存在,则删除,如果不存在,则提示删除失败。

要求4.删除完毕之后,遍历所有学生信息。

package heima.Test07;public class StudentTest01 {public static void main(String[] args) {//1.创建数组来存储学生对象Student[] arr = new Student[3];Student s1 = new Student(1, "liuneng", 18);Student s2 = new Student(2, "zhaoliu", 17);Student s3 = new Student(3, "li", 19);//2.把学生放进数组里面arr[0] = s1;arr[1] = s2;arr[2] = s3;//判断索引int count= contion(arr,2);if(count>=0){arr[count]=null;System.out.println("删除成功");//遍历数组printarr(arr);}else{System.out.println("不存在打印失败");}}//找到目标索引public static  int contion (Student[] arr,int count) {for (int i = 0; i < arr.length; i++) {Student s = arr[i];if (arr[i]!=null){int t= s.getID();if (t == 1){return i;}}}return -1;}public static  void printarr (Student[] arr) {for (int i = 0; i < arr.length; i++) {if (arr[i] != null) {System.out.println(arr[i].getID() + "\t" + arr[i].getName() + "\t" + arr[i].getAge());}}}
}

要求5.查询数组id为“2"的学生,如果存在,则将他的年龄+1岁

package heima.Test07;public class Student02 {public static void main(String[] args) {//1.创建数组来存储学生对象Student[] arr = new Student[3];Student s1 = new Student(1, "liuneng", 18);Student s2 = new Student(2, "zhaoliu", 17);Student s3 = new Student(3, "li", 19);//2.把学生放进数组里面arr[0] = s1;arr[1] = s2;arr[2] = s3;//先要找到ID为2的学生对于的索引int count= contion(arr,2);//判断索引if(count>=0){//将原来的年龄拿出来Student stu = arr[count];//将他的年龄+1int age = stu.getAge()+1;//将修改完的年龄修改stu.setAge(age);//遍历数组printarr(arr);}else{//不存在直接提示System.out.println("不存在打印失败");}}public static  int contion (Student[] arr,int count) {for (int i = 0; i < arr.length; i++) {Student s = arr[i];if (arr[i]!=null){int t= s.getID();if (t == count){return i;}}}return -1;}public static  void printarr (Student[] arr) {for (int i = 0; i < arr.length; i++) {if (arr[i] != null) {System.out.println(arr[i].getID() + "\t" + arr[i].getName() + "\t" + arr[i].getAge());}}}}
http://www.dtcms.com/wzjs/143429.html

相关文章:

  • 莱芜论坛二手车seo快速排名软件品牌
  • 永康物流网站百度sem是什么
  • 网站建设优化网站排名百度灰色关键词排名代做
  • 有没有帮忙做推广的网站网站广告投放价格表
  • 正规网站模板设计图百度官方
  • 做网站app怎么赚钱个人如何注册网站
  • 广州做网站海珠信科网站建设的基本流程
  • 雄安个人代做网站排名百度怎么进入官方网站
  • 北京做网站定制价格chrome下载
  • 网站 内页模板之家
  • 做购物类网站有哪些软文写作的十大技巧
  • 网站建设方案书要怎么样写最新新闻消息
  • 上海seo公司bwyseo怎么做网站关键词优化
  • 宁夏做网站的公司全网营销推广方案
  • 网站如何制作做吸引客户免费推广工具
  • 金华网站建设开发李守洪
  • 山西武汉网站建设免费的网络营销方式
  • 上海网页制作找哪家免费seo刷排名
  • 集团网站建设案例西安百度推广怎么做
  • 义乌网站建设联系方式小说网站排名
  • 网站虚拟主机有什么用百度做广告多少钱
  • 化妆品网站程序免费网站免费
  • 环球设计官网网站上海网站制作公司
  • ps做网站的优点关键词在线试听免费
  • 网站访问速度优化怎么让关键词快速上首页
  • 黄金网站网址免费前端seo是什么
  • 江阴做公司网站有哪些58精准推广点击器
  • 在国外社交网站做产品推广网络销售网站
  • 网站建站啥意思河南郑州最新消息今天
  • 做网站用ui好还是ps必应搜索引擎网址