有带参方法实现查找一个学生类数组里的一个学生姓名

package Month.JUL.JUL09;

//学员类
public class Student {
    String name;
    public Student() {}
    public Student(String name) {
        this.name = name;
    }
}


package Month.JUL.JUL09;

import java.util.Scanner;

public class Test02 {
    static Scanner input = new Scanner(System.in);

    public void chaZhao(int start, int end, String stu, Student[] stus) {

        for (int i = (start - 1); i < end; i++) {
            if (stus[i].name.equals(stu)) {
                System.out.println("找到了,在第" + (i + 1) + "个位置!");
                return;
            }
        }
    }

    public static void main(String[] args) {
        Student[] stus = new Student[10];
        for (int i = 0; i < 10; i++) {
            stus[i] = new Student("张" + (i + 1));
        }

        System.out.println("请输入开始查找的位置(1~10之间):");
        int start = input.nextInt();
        System.out.println("请输入结束查找的位置(1~10之间):");
        int end = input.nextInt();
        System.out.println("请输入要查找的人的姓名:");
        String st = input.next();
        Student stu = new Student(st);
        Test02 ca = new Test02();
        ca.chaZhao(start, end, st, stus);

    }

}

 

转载于:https://www.cnblogs.com/zeng1997/p/11158394.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值