国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

Java:集合,ArrayList,請選擇你要執(zhí)行的功能1.查詢2.添加3.修改4.刪除,增刪改查

2020-03-12 18:54 作者:詩書畫唱  | 我要投稿

實現(xiàn)有功能“1.查詢2.添加3.修改4.刪除”的和ArrayList有關(guān)的程序


package a;


import java.util.ArrayList;

import java.util.Scanner;


public class lizi {


public static void main(String[] args) {


ArrayList<student> arr = new ArrayList<student>();


arr.add(new student(1, "詩名", '男', 95));


arr.add(new student(2, "書名", '男', 92));


arr.add(new student(3, "畫名", '男', 90));


arr.add(new student(4, "唱名", '男', 111));


arr.add(new student(5, "帥名", '男', 134));

while (true) {

System.out.println("請選擇你要執(zhí)行的功能1.查詢2.添加3.修改4.刪除");

Scanner s = new Scanner(System.in);

int num = s.nextInt();

if (num == 1) {

// 查詢:

System.out.println("執(zhí)行查詢功能");

for (student i : arr) {

System.out.println(i);

}

} else if (num == 2) {

// 添加:

System.out.println("已經(jīng)執(zhí)行添加“3, “張三”, '男', 88”功能,不信可執(zhí)行查詢功能");

arr.add(new student(3, "張三", '男', 88));

} else if (num == 3) {

// 修改:

System.out.println("執(zhí)行修改功能");

System.out.println("請輸入你要修改的學(xué)生的編號");

int bianhao = s.nextInt();

for (int i = 0; i < arr.size(); i++) {

if (bianhao == arr.get(i).bianhao) {

System.out.println("你要修改的成績?yōu)槎嗌?");

double d = s.nextDouble();

arr.get(i).ChengJi = d;

}

}

} else if (num == 4) {

// 刪除:

System.out.println("執(zhí)行刪除功能");

System.out.println("請輸入你要刪除的學(xué)生的編號");

int bianhao = s.nextInt();

for (int i = 0; i < arr.size(); i++) {

if (bianhao == arr.get(i).bianhao) {

arr.remove(arr.get(i));

}

}

System.out.println("刪除完畢");

}

}

}

}



class student {


int bianhao;


double ChengJi;


String name;


char sex;


public student(int bianhao, String name, char sex, double ChengJi) {


this.bianhao = bianhao;


this.name = name;


this.sex = sex;


this.ChengJi = ChengJi;


}


@Override

public String toString() {


return "編號:" + bianhao + ",\t名字:" + name + ",\t性別:" + sex + ",\t成績:"


+ ChengJi;


}


}


Java:集合,ArrayList,請選擇你要執(zhí)行的功能1.查詢2.添加3.修改4.刪除,增刪改查的評論 (共 條)

分享到微博請遵守國家法律
建平县| 上栗县| 绥宁县| 华容县| 饶阳县| 杨浦区| 任丘市| 香格里拉县| 页游| 平利县| 乡城县| 湖南省| 金坛市| 通山县| 平定县| 会东县| 鄢陵县| 廊坊市| 从化市| 大连市| 博客| 栾川县| 公安县| 彭阳县| 海晏县| 漳平市| 凤翔县| 海伦市| 海口市| 西和县| 农安县| 龙川县| 曲麻莱县| 徐汇区| 肃宁县| 基隆市| 宁武县| 嘉兴市| 东源县| 三穗县| 大埔区|