标签:
1 package com.qingdaoligong.jierui; 2 public class CustomerBiz { 3 String[] shuzu = new String[5]; 4 int j; 5 boolean qw = false;//定义一个布尔变量 6 boolean qw1 = false;//定义一个布尔变量 7 public void addName(String name1, int i) { 8 shuzu[i] = name1; 9 } 10 public void showName() { 11 System.out.println("*******************"); 12 System.out.println("\t客户信息表"); 13 System.out.println("*******************"); 14 for (String x : shuzu) { //依次输出数组内信息 15 System.out.print("客户:" + x); 16 } 17 System.out.print("\n"); 18 } 19 public boolean search(int start, int end, String name2) { 20 for (int k = start; k < end; k++) { //在指定索引范围内循环 21 if (shuzu[k].equals(name2)) { 22 qw = true; 23 break; 24 } 25 } 26 return qw;//返回一个布尔数据 27 } 28 public boolean search1(String name3,int i) { 29 for(int j=0;j<i;j++){ 30 if(shuzu[j].equals(name3)){ 31 qw1=true; 32 break; 33 } 34 } 35 return qw1; 36 } 37 }
1 package com.qingdaoligong.jierui; 2 import java.util.Scanner; 3 public class CustomerBizTest { 4 public static void main(String[] args) { 5 String name1 = "0"; 6 String name2; 7 String name3; 8 Scanner input = new Scanner(System.in); 9 CustomerBiz name = new CustomerBiz(); 10 String Y = "n"; 11 int i = 0; 12 do { 13 Y = "n"; 14 System.out.print("请输入客户的姓名:"); 15 name1 = input.next(); 16 name.addName(name1, i);//调用addName方法 17 i++; 18 System.out.print("继续输入吗?(y/n):"); 19 Y = input.next(); 20 } while (Y.equals("y")); 21 name.showName(); 22 System.out.println("请输入需要查找的客户姓名:"); 23 name3=input.next(); 24 boolean chazhao = name.search1(name3, i); 25 if(chazhao){ 26 System.out.println("找到了:"); 27 }else{ 28 System.out.println("没有找到了"); 29 } 30 System.out.println("请输入姓名:"); 31 name2 = input.next(); 32 System.out.println("开始索引:"); 33 int start = input.nextInt(); 34 System.out.println("结束索引:"); 35 int end = input.nextInt(); 36 boolean result = name.search(start, end, name2); 37 if(result){ 38 System.out.println("找到该学生"); 39 }else{ 40 System.out.println("没找到该学生"); 41 } 42 input.close(); 43 } 44 }
标签:
原文地址:http://www.cnblogs.com/infernofranz/p/5735382.html