怎么改这段java程序让它运行

[复制链接]
查看11 | 回复5 | 2009-5-21 09:28:19 | 显示全部楼层 |阅读模式
outputElements的参数是String的数组,虽然参数名和类名一样,但也只是作为形参,一样不一样都没影响。StudentName sn=new StudentName(); sn.outputElements(StudentName[0]); StudentName[0]是哪来的东西?你跟本没有定义过StudentName这个变量,而且由于和类名一样,你也无法定义这个名称的变量。虽然不清楚你要做什么,不过改成这样应该就行了StudentName sn=new StudentName(); sn.outputElements(new String[1]); //自己定义下数组长度,这里随便写的1。说实话不知道运行...
回复

使用道具 举报

千问 | 2009-5-21 09:28:19 | 显示全部楼层
StudentName[0]="zhangsan"; 意思是这个数组有0个元素!!!!...
回复

使用道具 举报

千问 | 2009-5-21 09:28:19 | 显示全部楼层
不知道这个是不是楼主想要的:public class StudentName { public void outputElements(String StudentName[]) { //StudentName[0]="zhangsan"; for (int i=0;i<StudentName.length;i++) Syst...
回复

使用道具 举报

千问 | 2009-5-21 09:28:19 | 显示全部楼层
main方法中这么改StudentName[] sn=new StudentName[2]; sn.outputElements(sn[0]);...
回复

使用道具 举报

千问 | 2009-5-21 09:28:19 | 显示全部楼层
1.你看你调用这个方法中的数组,时, 是找不到 StudentName[0]="zhangsan"; 你把它定义在了,方法体内。要提出来。 改了一下: public class Test //StudentName { static String StudentName[] = new String[]{"zhangs...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行