即日起在codingBlog上分享您的技术经验即可获得积分,积分可兑换现金哦。

( ).equals.( )

编程语言 lijia111111 19℃ 0评论

输入变量与实际变量相匹配

import java.util.Scanner;
public class Text1
{
    public static void main(String [] args)
    {
        Scanner sc=new Scanner(System.in);
        connect b=new connect();
        System.out.println("请输入联系人数量");
        int n=sc.nextInt();
        System.out.println("请输入"+n+"个联系人姓名和电话");
        for(int i=1;i<=n;i++)
        {
            String name=sc.next();
            String number=sc.next();
            System.out.println(b.add(name,number));
        }
        System.out.println("全部的联系人为");
        b.look();
        System.out.println("请输入查找姓名");
        String seekname=sc.next();
        if((b.seek(seekname))==null)
        System.out.println("未找到");
        System.out.println((b.seek(seekname)).name+" "+(b.seek(seekname)).number);
        System.out.println("请输入删除姓名");
        String deletename=sc.next();
        System.out.println( b.delete(deletename));
        System.out.println("全部的联系人为:");
        b.look();
    }
}
class Person
{
    String name;
    String number;
}
class connect
{
    Person a[];
    int number;

    public connect()
    {
        a = new Person[100];
        number = 0;
    } 

    public String add(String name,String number)
    {
        if(this.number>99)
        return "添加失败";
        a[this.number]=new Person();
        a[this.number].name=name;
        a[this.number].number=number;
        this.number++;
        return "添加成功";
    }   

    public Person seek(String name)
    {
        for(int i=0;iif((a[i].name).equals(name))//输入变量与实际变量相匹配
            {
                return a[i];
            }
        }
        return null;    
    }

    public void look()
    {
        for(int i=0;iout.println("联系人 "+a[i].name+" 电话 "+a[i].number);
        }
    }

    public String delete(String name)
    {
        for(int i=0;iif((a[i].name).equals(name))
          {
            a[i]=a[this.number-1];
            number=number-1;
            return "删除成功";
          }
        }
        return "删除失败";
    }
}

转载请注明:CodingBlog » ( ).equals.( )

喜欢 (0)or分享 (0)
发表我的评论
取消评论

*

表情