当我编译以下代码时,会出现一条错误消息
Error: Could not find or load main class javaapplication6.JavaApplication6
Java Result: 1.
我使用的软件是Netbeans IDE8.0
import java.util* ;
package javaapplication6 ;
public class JavaApplication6 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in) ;
System.out.println ("Please enter your user name!");
String userName = in.nextline ();
System.out.println("please enter the passcode" + userName + ".");
int passcodeFromUser = in.next.Int ();
int passcode = 7001 ;
if (passcodeFromUser == passcode)
{
System.out.println("welcome" + username + "!" );
}
else
{
System.out.println("Acess Denied");
}
}
}
答案 0 :(得分:1)
您必须将package语句声明为类的第一个语句,如下所示
package javaapplication6 ;
import java.util.*;
答案 1 :(得分:1)
您的包声明应始终位于导入之前。通常,您的代码不应该首先编译。
答案 2 :(得分:0)
当我在我的编辑器中复制你的代码时,我发现它有很多错误..这会有效..
package javaapplication6 ;
import java.util.*;
public class JavaApplication6 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in) ;
System.out.println ("Please enter your user name!");
String userName = in.nextLine ();
System.out.println("please enter the passcode" + userName + ".");
int passcodeFromUser = in.nextInt ();
int passcode = 7001 ;
if (passcodeFromUser == passcode)
{
System.out.println("welcome" + userName + "!" );
}
else
{
System.out.println("Acess Denied");
}
}
}
以下是我的更改..
的java.util *; >> java.util中。*;
in.nextline(); >> in.nextLine();
in.next.Int(); >> in.nextInt();
System.out.println(“welcome”+ username +“!”); >> System.out.println(“welcome”+ userName +“!”);
答案 3 :(得分:0)
尝试将包声明更改为
package javaapplication6 ;
import java.util* ;