⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dataarray.java

📁 java 数据结构的一些简单实例和一些线程的应用主要是面向初学者
💻 JAVA
字号:
import java.io.*;
class Person{
	private String firstname;
	private String lastname;
	private int age;
	
	public Person(String first,String last,int age1){
		firstname=first;
		lastname=last;
		age=age1;
	}
	public void display(){
		System.out.println("the firstname is"+firstname);
		System.out.println("the lastname is "+lastname);
		System.out.println("the age is "+age);
	}
	public String getLastname(){
		
		return lastname;
	}
}

class ClassData{
	private Person[] p;
	private int length;
	
	public ClassData(int max){
		p=new Person[max];
		length=0;
	}
	public void insert(String first,String last,int age2){
		p[length]=new Person(first,last,age2);
		length++;
	}
	public boolean Found(String searchkey){
		int j;
		for(j=0;j<length;j++)
			if(p[j].getLastname().equals(searchkey))
				break;
		if(j==length)
			return false;
		else
			return true;
	}
	public boolean delete(String searchkey){
		int j;
		for(j=0;j<length;j++)
			if(p[j].getLastname().equals(searchkey))
				break;
		if(j==length)
		     return false;
		else
		{
			for(int i=j;i<length;i++)
				p[i]=p[i+1];
			length--;
			return true;
		}
	}
	public void displayClassData(){
		for(int i=0;i<length;i++)
			p[i].display();
	}
	
}

class DataArray{
	public static void main(String[] args)throws IOException{
		int max=100;
		ClassData cd=new ClassData(max);
		 cd.insert("yuan","pei",18);
		 cd.insert("yuan","fei",20);
		 cd.insert("yuan","bing",24);
		 cd.insert("yuan", "jun", 28);
		 cd.displayClassData();
		 System.out.println("please enter the searchkey");
		 String s=getString();
		 boolean found=cd.Found(s);
		 if(found==true)
			 System.out.println("found the searchkey"+" "+s);
		 else
			 System.out.println("can't found the searchkey"+" "+s);
		 System.out.println("please enter the searchkey");
		 String b=getString();
		 cd.delete(b);
		 cd.displayClassData();
	}
    public static String getString()throws IOException{
    	InputStreamReader isr=new InputStreamReader(System.in);
        BufferedReader br=new BufferedReader(isr);
        String s=br.readLine();
        return s;
    }
	
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -