<上机练习>

练习1:
package com.mm;

import java.util.*;

public class stu {
	String[] g = new String[5];

	public void fell(String name) {
		for (int i = 0; i < g.length; i++) {
			if (g[i] == null) {
				g[i] = name;
				break;
			}
		}

	}

	public void showstu() {
		for (int i = 0; i < g.length; i++) {
			if (g[i] != null) {
				System.out.println(g[i]);
			}
		}
	}

	public void show() {
		for (int i = 0; i < g.length; i++) {
			System.out.println("请输入客户姓名:");
			Scanner input = new Scanner(System.in);
			String name = input.next();
			fell(name);

		}
		System.out.println("**********************************");
		System.out.println("\t客户姓名列表");
		System.out.println("**********************************");
		showstu();

	}

	public void showeet(String old, String newname, String[] g) {
		for (int i = 0; i < g.length; i++) {
			if (g[i].equals(old)) {
				g[i] = newname;
			}
		}
		/*
		 * for (int i = 0; i < g.length; i++) { System.out.println(g[i]); }
		 */
		showstu();

	}

}

package com.mm;

public class stu11 {
	public static void main(String[] args) {
		stu u = new stu();
		u.show();
		u.showeet("学生1", "王羲之", u.g);

	}
}

练习2:
package com.ss;

public class stu {
String name;
int age;

public void showent(){
	
	System.out.println(name+"\t"+age);
}


}

package com.ss;

public class stu1 {
stu[] g=new stu[5];
public void add(stu student){
	for(int i=0;i<g.length;i++){
		if(g[i]==null){
			g[i]=student;
			break;
		}
	}
}
	
public void showtil(){
	for(int i=0;i<g.length;i++){
		if(g[i]!=null){
			g[i].showent();
		}
	}
	System.out.println();
}

}

package com.ss;

public class stu2 {
public static void main(String[] args) {
	stu h=new stu();
	h.age=13;
	h.name="小轩";
	stu k=new stu();
	k.age=14;
	k.name="小华";
	stu1 gg=new stu1();
	gg.add(h);
	gg.add(k);
	gg.showtil();
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值