这个问题可能需要一些编译器知识才能回答.我目前正在开发一个项目,我将创建一个可能是其中的数组
int[2][veryLargeNumber]
Run Code Online (Sandbox Code Playgroud)
要么
int [veryLargeNumber][2]
Run Code Online (Sandbox Code Playgroud)
它在逻辑上没有区别,但我认为内存中的形式(以及因此大小)可能不同(也许问题应该是,编译器是否足够聪明地重新排列数组以适应它们)?
我在这个Point3f数组上有一个空指针异常错误,无法看到原因.它发生在第一次通过,选择位置[0].任何人都能解释一下吗?谢谢.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.vecmath.Point3f;
public class Starter {
static int NoOfSides = 4;
public static void main(String[] args) {
Point3f[] pointArray = new Point3f[NoOfSides];
for(int i=0; i<NoOfSides; i++)
{
System.out.println(i+1+". Input x value: ");
pointArray[i].x=readConsole(); // Pointer Exception Here
System.out.println(i+1+". Input y value: ");
pointArray[i].y=readConsole();
pointArray[i].z=(float)0.0;
}
// Static call to work out area of polygon
System.out.println("Area: "+PolyAreaTry.CalArea(pointArray));
}
public static float readConsole()
{
String s = null;
try
{
BufferedReader bufferRead = new BufferedReader(new …Run Code Online (Sandbox Code Playgroud)