【发布时间】:2016-02-26 23:55:44
【问题描述】:
我是 Java 新手,我有一个代码,其中有一个包。我的问题是我试图在 Jgrasp 上运行代码,这是我的学校程序来运行代码。 Jgrasp 不使用包。由于包的原因,我无法运行它。我不知道包是如何工作的,但我为此编写了一个完整的代码并将其提供给了一个朋友,他编辑了我的代码并将其制成一个包并说它可以工作。我不要包,我要的是他写的完整代码,而不是下面的 main 方法。
package insta2;
import java.io.*;
import java.util.*;
class BottomUpApp {
public static void main(String[] args) throws IOException {
BottomUp bup;
Tree theTree = null;
int value;
String str;
while (true) {
System.out.print(" Enter first letter of balanced");
System.out.print(" unbalanced , show , or traverse : ");
int choice = getChar();
switch (choice) {
case 'b':
System.out.print(" Enter string : ");
str = getString();
bup = new BottomUp(str);
bup.balanced();
theTree = bup.getTree();
break;
case 'u':
System.out.print("Enter string: ");
str = getString();
bup = new BottomUp(str);
bup.unbalanced();
theTree = bup.getTree();
break;
case 's':
theTree.displayTree();
break;
case 't':
System.out.print(" Enter type 1, 2 or 3 : ");
value = getInt();
theTree.traverse(value);
break;
default:
System.out.print(" Invalid entry \n ");
}
}
}
public static String getString() throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String s = br.readLine();
return s;
}
public static char getChar() throws IOException {
String s = getString();
return s.charAt(0);
}
public static int getInt() throws IOException {
String s = getString();
return Integer.parseInt(s);
}
}
【问题讨论】:
-
对不起,这个问题毫无意义。我在您发布的代码中看到了您的包和两个来自 Java 的包。你想看什么,为什么?
-
我想查看包 insta2 代码。我猜这个包有一个书面代码?
-
这就是你让我困惑的原因。 “package insta2”位于您发布的代码的顶部。您发布的课程在该包中。你有代码。你是说还有更多吗?这是你写的还是别人写的?如果是后者,请执行与发布问题相同的操作。我再问一遍:你真正的问题是什么?如果您只有一个带有已编译字节码的 JAR,您可以随时使用 IntelliJ 等智能 IDE 查看反编译的源代码。你真正的问题是什么?
-
我的问题是我试图在 Jgrasp 上运行代码,这是我的学校程序来运行代码。由于包的原因,我无法运行它。我不知道包是如何工作的,但我为此编写了一个完整的代码并把它交给了一个朋友,他把它做成了一个包并说它可以工作。我不想要包,我想要完整编写的代码,而不是 main 方法。
-
你是什么意思因为包的原因不能运行?你的意思是你必须在你的 CLASSPATH 中添加一个 JAR 吗?您需要学习如何做到这一点,而不是在 main 中包含源代码。