I'm trying to write a method to print each row of my two-dimensional array of doubles, called 'M', and I've written the following print method.
public void print()
{
for (i = 0;i < size;i++)
{
System.out.println();
for (j = 0;j < size;j++)
{
System.out.println(M[j] + ""
}
}
}
The class compiles fine, but when I run the driver program I get a null pointer exception error, which points directly to the line that says "System.out.println(M[j] + """. Any ideas on why that may be? At first someone suggested that I wasn't converting the double to a String, but I figured if I had (M[j] + "", that would convert the double to a String. I also tried to do toString(M[j]), but got a completely different error when I compiled the class, so I knew that wouldn't work.
Any suggestions?
Thanks in advance!
public void print()
{
for (i = 0;i < size;i++)
{
System.out.println();
for (j = 0;j < size;j++)
{
System.out.println(M[j] + ""
}
}
}
The class compiles fine, but when I run the driver program I get a null pointer exception error, which points directly to the line that says "System.out.println(M[j] + """. Any ideas on why that may be? At first someone suggested that I wasn't converting the double to a String, but I figured if I had (M[j] + "", that would convert the double to a String. I also tried to do toString(M[j]), but got a completely different error when I compiled the class, so I knew that wouldn't work.
Any suggestions?
Thanks in advance!