zoukankan      html  css  js  c++  java
  • CustomerBiz方法运用

    package FacePro;
    
    import java.util.Scanner;
    
    public class CustomerBizTesr {
    
        public static void main(String[] args) {
            CustomerBiz a = new CustomerBiz();
            Scanner scanner = new Scanner(System.in);
            for (int i = 0; i < 5; i++) {
                    System.out.println("请输入客户的姓名:");
                    String name = scanner.next();
                    a.addName(i,name);
                    System.out.println("继续输入吗?(y/n)");
                    String s = scanner.next();
                    if(!s.equals("y")){
                        break;
                    }
            }
            a.showName();
            System.out.println("");
            System.out.print("请输入开始查找的位置:");
            int star = scanner.nextInt();
            System.out.print("请输入结束查找的位置:");
            int end = scanner.nextInt();
            System.out.print("请输入查找的姓名:");
            String name = scanner.next();
            System.out.println("*****查找结果******");
            boolean b = a.search(star, name, end);
            if(b){
                System.out.println("找到该学生!");
            }
            else{
                System.out.println("没有找到该学生!");
            }
            scanner.close();
        }
    
    }
    package FacePro;
    
    public class CustomerBiz {
        //声明属性
        String [] names = new String[5];
        
        //方案一:数组拼接为字符串
        //StringBuffer sb = new StringBuffer();
        //声明方法
        public void addName(int i,String name){
            names[i] = name;
            
           // sb.append(names[i]);     //方案一
        }
        public void showName(){
            System.out.print("输入的全部姓名为:");
            for(String na:names){
                System.out.print(na+"	");
            }
        }
        public boolean search(int star ,String name,int end){
            //方案一:根据索引范围查找
            /*boolean b = true;
            int i = sb.indexOf(name);
            if (i < star || i >end){
                b = false;
            }
            return b;*/
            
            //方案二:根据name查找
            boolean y = false;
            for(int i=star; i <= end ; i++){
                if(names[i].equals(name)){
                    y = true;
                    break;
                }
            }
            return y;
            
        }
    }

  • 相关阅读:
    每天干的啥?(2021.1)
    每天干的啥?(2020.12)
    每天干的啥?(2020.11)
    每天干的啥?(2020.10)
    每天干的啥?(2020.9)
    每天干的啥?(2020.8)
    每天干的啥?(2020.7)
    每天干的啥?(2020.6)
    每天干的啥?(2020.5)
    每天干的啥?(2020.4)
  • 原文地址:https://www.cnblogs.com/xiaolei121/p/5734093.html
Copyright © 2011-2022 走看看