I've got this code:
@Override
public int compareTo(LargeInt passedIn)//
{
if(passedIn == null)
{
throw new RuntimeException("NullExceptionError");
}
int ewu = 0;
int avs = 0;
if(this.myArray.length != passedIn.myArray.length)
{
return this.myArray.length - passedIn.myArray.length;
}
for(this.myArray.length == passedIn.myArray.length)
{
}
for(int x = 0; x < this.myArray.length; x++)
{
ewu += this.myArray[x];
}
for(int x = 0; x < passedIn.myArray.length; x++)
{
avs += passedIn.myArray[x];
}
return ewu - avs;
}
My goal is, under this line:
for(this.myArray.length == passedIn.myArray.length)
I want to If the lengths are equal, go through the array until a value that is different is found. Then subtract those two values and return. How might I go about doing this?
if(passedIn == null) { throw new RuntimeException("NullExceptionError"); }? If you check fornulljust to throw an Exception, then just remove that check. You'll get your desiredNullPointerExceptionif the variable isnull"automatically".for(this.myArray.length == passedIn.myArray.length)loop.forso just use another one and useif (myArray[x] != passedIn.myArray[x]) { }inside.