我制作了一个基本的 Java 程序,上面写着“hello world”
我使用javac
命令编译它并使用java
命令运行它,一切正常,我在 NetBeans 中制作了一个“复杂”(需要导入随机数和扫描仪才能工作)程序,导出它并使用javac
CMD 中的命令编译源代码但是当我尝试运行它时,会发生这种情况:
仅当我尝试使用在文件中使用“导入”命令的代码时才会发生这种情况
编辑:
我尝试了“javac asd.java”和“java Asd.java”,两者都工作然后我尝试了“java Asd”和“java asd”,没有工作,它一直给我上面的错误,代码:
package asd;
import java.util.Scanner;
import java.util.Random;
public class Asd{
public static void main(String[] args) {
Random r = new Random();
Scanner scan = new Scanner(System.in);
System.out.println("Choose a difficulty");
boolean s = true;
int v = 0;
while(true){
System.out.println("Very Easy/Easy/medium/hard/impossible/impossibler");
System.out.print("I want it to be ");
String x = scan.nextLine();
if (x.equalsIgnoreCase("very easy")){
v = 6;
break;
}
else if (x.equalsIgnoreCase("easy")){
v = 11;
break;
}
else if (x.equalsIgnoreCase("medium")){
v = 26;
break;
}
else if (x.equalsIgnoreCase("hard")){
v = 51;
break;
}
else if (x.equalsIgnoreCase("impossible")){
v = 101;
break;
}
else if (x.equalsIgnoreCase("impossibler")){
s = false;
break;
}
else {
System.out.println("invalid difficulty");
}
}
v--;
int h = 0;
int c = 0;
if(s){
System.out.println("Guess a number beween 0 and " + v);
c = r.nextInt(v);
//int i = 0;
while (true) {
String b = scan.nextLine();
int g;
try {
g = Integer.parseInt(b);
if (g < c){
System.out.println("Try higger");
}
else if (g > c){
System.out.println("Maybe less");
}
else {
break;
}
}
catch (Exception e) {
System.err.println("please use a number");
}}}
else {
System.out.println("Guess a number between 0 and 999999999");
while(true) {
c = r.nextInt();
if ((c < 0) && (c > 999999999)) {}
else {
break;
}}
while(true) {
String b = scan.nextLine();
try {
int g;
g = Integer.parseInt(b);
if (g < c){
System.out.println("Try higger");
}
else if (g > c){
System.out.println("Maybe less");
}
else {
break;
}
}catch(Exception e){
System.out.println("please use a number");
}}
}
System.out.println("YOU WIN");
System.out.print("push enter to quit");
String k = scan.nextLine();
}
}
这是我制作的一个小游戏,但不仅仅是这段代码,我制作的任何东西都需要导入一些东西,当它在 netbeans/eclipse 之外运行时不起作用