该程序采用现实生活中的物体及其权重,并根据字母顺序对其进行排序,然后按数字排序
但问题是,当我在 Eclipse 中运行此应用程序(尚未在 NetBeans 中尝试过)时,它运行良好,但是当我编译并尝试在终端中运行它时,它不起作用并出现错误,“不能找到主要课程”
请记住我的java文件和class文件在同一个文件夹中,所以目录不是问题
public class testMain {
public static void main(String[] args) {
//makes a new multidimensial array
//the first dimension holds the name of the object
//the second dimension holds the weight
//the 4's in this case show the maximum space the array can hold
String[][] objectList = new String[4][4];
objectList[1][0] = "Teapot";
objectList[0][1] = String.valueOf(1);
objectList[2][0] = "Chesterfield";
objectList[2][2] = String.valueOf(120);
objectList[3][0] = "Laptop";
objectList[3][3] = String.valueOf(6);
//printing the array
for (int i = 1; i < 3; i++) {
for (int j = 0; j < 3;) {
System.out.println(objectList[i][j].toString());
}
}
}
}
按要求:在我输入的命令行中,
cd /Users/username/Desktop/JavaProjects
javac ojArray.java
(After it compiled)
java ojArray.class