第十四章 上机练习2

    xiaoxiao2022-06-30  59

    //上机练习2 import java.util.Scanner; public class Qing6 { String[] names = new String[10]; public void addName(String name) { for (int i = 0; i < names.length; i++) { if (names[i] == null) { names[i] = name; break; } } } public void showNames() { System.out.println("******************"); System.out.println("客户姓名列表:"); System.out.println("******************"); for (int i = 0; i < names.length; i++) { System.out.println(names[i] + " "); } } public boolean chazhao(int start, int end, String name, String name4) { boolean find = false; for (int i = start - 1; i < end; i++) { if (names[i].equals(name)) { find = true; names[i] = name4; break; } } return find; } public static void main(String[] args) { Qing6 a = new Qing6(); Scanner input = new Scanner(System.in); String names; for (int i = 0; i < a.names.length; i++) { System.out.println("请输入客户姓名:"); names = input.next(); a.addName(names); } a.showNames(); System.out.println("\n请输入要修改的学生姓名:"); String name=input.next(); System.out.println("\n请输入新的学生姓名:"); String names1=input.next(); if(a.chazhao(1,10,name,name)){ System.out.println("******修改结果为*******"); System.out.println("找到并修改成功"); a.showNames(); } } }
    转载请注明原文地址: https://ju.6miu.com/read-1126052.html

    最新回复(0)