请帮我看看这段java 程序哪里出错了。
publicclassImprovedPartialSum{privatestaticfinalintMAX_INDEX=9;publicstaticvoidmain(S...
public class ImprovedPartialSum
{
private static final int MAX_INDEX=9;
public static void main(String[] args)
{
Change[] c=new Change[9];
String mark;
int num=0;
String[] s=new String[MAX_INDEX];
for(int i=0;i<MAX_INDEX;i++)
{
num=num+(i+1)*(i+1);
if(num%2==0)
{
c[i].getisEven(true);
mark="*";
s[i]=mark;
}
else
{
c[i].getisEven(false);
mark="";
s[i]=mark;
}
System.out.println((i+1)+":"+num);
}
}
}
class Change
{
public int sum;
public boolean isEven;
public void getsum(int x)
{
sum=x;
}
public void getisEven(boolean x)
{
isEven=x;
}
}
我觉得没有错。他提示我c[i].getisEven(false);这行有误,原因是Exception in thread "main" java.lang.NullPointerException
at improved.ImprovedPartialSum.main(ImprovedPartialSum.java:23) 展开
{
private static final int MAX_INDEX=9;
public static void main(String[] args)
{
Change[] c=new Change[9];
String mark;
int num=0;
String[] s=new String[MAX_INDEX];
for(int i=0;i<MAX_INDEX;i++)
{
num=num+(i+1)*(i+1);
if(num%2==0)
{
c[i].getisEven(true);
mark="*";
s[i]=mark;
}
else
{
c[i].getisEven(false);
mark="";
s[i]=mark;
}
System.out.println((i+1)+":"+num);
}
}
}
class Change
{
public int sum;
public boolean isEven;
public void getsum(int x)
{
sum=x;
}
public void getisEven(boolean x)
{
isEven=x;
}
}
我觉得没有错。他提示我c[i].getisEven(false);这行有误,原因是Exception in thread "main" java.lang.NullPointerException
at improved.ImprovedPartialSum.main(ImprovedPartialSum.java:23) 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询