Topic: Exception in thread"main"ArrayIndexoutOfbound |
Print this page |
1.Exception in thread"main"ArrayIndexoutOfbound | Copy to clipboard |
Posted by: april518 Posted on: 2004-11-26 16:23 code as : /** * AWT Sample application * * @author * @version 1/<.00 04%m>/26 */ class Employer { public String name; public float salary; public Employer (String a,float b){ name=a; salary=b; } public String getName(){ return name ; } public float getSalary(){ return salary; } public void salaryRaise(double raise){ double incresement=salary*raise/100; salary+=incresement; } } public class EmployerTest { /** * Method main * * * @param args * */ public static void main (String[] args) { // TODO: Add your code here EmployerFrame frame=new EmployerFrame(); frame.setVisible(true); Employer[] staff=new Employer[3]; staff[0]=new Employer("Harry",1230); staff[1]=new Employer("Jack",1330); staff[2]=new Employer("Sam",5463); for(int i=0;i<=staff.length;i++){ staff[i].salaryRaise(10); } for(int i=0;i<=staff.length;i++){ Employer e=staff[i]; System.out.println("name:"+e.getName()+ ",salary:"+e.getSalary()); } } } 问题就好像在黑体那一段!请各位大哥帮忙啦!3Q! |
2.Re:Exception in thread"main"ArrayIndexoutOfbound [Re: april518] | Copy to clipboard |
Posted by: why Posted on: 2004-11-26 19:28 for(int i=0; i<staff.length; i++){ Java's array is zero-based. otherwise staff[staff.length] would result in the ArrayIndeOutOfboundExcpetion |
3.Re:Exception in thread"main"ArrayIndexoutOfbound [Re: april518] | Copy to clipboard |
Posted by: HJILY44 Posted on: 2004-11-27 10:25 <=明显越界 |
4.Re:Exception in thread"main"ArrayIndexoutOfbound [Re: april518] | Copy to clipboard |
Posted by: april518 Posted on: 2004-11-27 20:14 谢谢大哥!我明白了!运行正常了!可是依旧出现了一个Exception:ArrayIndeOutOfboundExcpetion :3 这个影响程序运行吗?如何解决这个问题!还请大哥赐教!小弟谢过了! |
5.Re:Exception in thread"main"ArrayIndexoutOfbound [Re: april518] | Copy to clipboard |
Posted by: april518 Posted on: 2004-11-27 20:16 谢谢大哥!我明白了!运行正常了!可是依旧出现了一个Exception:ArrayIndeOutOfboundExcpetion :3 这个影响程序运行吗?如何解决这个问题!还请大哥赐教!小弟谢过了! |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |