java-第十三章-类的无参方法(一)-查找客户姓名
package 上机练习; public class A02class { String names[] = new String[30]; public void showA(String name) { for (int i = 0; i < names.length; i++) { if (names[i] == null) { names[i] = name; break; } } } public void showB() { System.out.println("\t客户列表显示"); for (int i = 0; i < names.length; i++) { if (names[i] != null) { System.out.print(names[i] + "\t"); } } } public boolean showC(String find) { boolean con = false; for (int i = 0; i < names.length; i++) { if (names[i] != null) { if (names[i].equals(find)) { con = true; break; } } } return con; } } package 上机练习; import java.util.Scanner; public class A02 { public static void main(String[] args) { // TODO Auto-generated method stub A02class A02 = new A02class(); Scanner in = new Scanner(System.in); boolean con = true; while (con) { System.out.println("请输入客户的姓名:"); String admin = in.next(); A02.showA(admin); System.out.println("请输入是否继续:(y / n ):"); String choice = in.next(); if (choice.equals("n")) { con = false; break; } } A02.showB(); System.out.println("请输入要查找的客户的姓名:"); String find = in.next(); if (A02.showC(find)) { System.out.println("有"); } else { System.out.println("没有"); } } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。