import java.util.*;
public class Student {
String[] names=new String[10];
public void addName(String name){
for(int i=0; i<names.length; i++){
if(names[i]==null){
names[i]=name;
break;
}
}
}
public void showName(){
for(int i=0; i<names.length; i++){
System.out.print(names[i]+" ");
}
}
public boolean searchName(int start,int end,String name){
boolean find=false;
for(int i=start-1;i<end;i++){
if(names[i].equals(name)){
find=true;
break;
}
}
return find;
}
public static void main(String[] args){
Scanner input=new Scanner(System.in);
Student s=new Student();
for(int i=0; i<10; i++){
System.out.print("请输入学生姓名: ");
String newname=input.next();
s.addName(newname);
}
System.out.println();
System.out.print("输入开始的位置: ");
int a=input.nextInt();
System.out.print("输入结束的位置: ");
int b=input.nextInt();
System.out.print("输入查找的学生姓名: ");
String name=input.next();
if(s.searchName(a,b,name)){
System.out.println("找到了");
}else{
System.out.println("没找到该学生");
}
s.showName();
}
}
转载请注明原文地址: https://ju.6miu.com/read-1126095.html