这个错误在java中意味着什么?
what does this error means in java?
我是 java 中的编程新手,不知道这些错误的含义:
Gamelauncher.java:11: error: class player is public, should be declared in a file named player.java
public class player{
^
Gamelauncher.java:30: error: class playgame is public, should be declared in a file named playgame.java
public class playgame{
^
2 errors
源代码:
public class Gamelauncher{
public static void main(String[] args){
playgame game = new playgame();
game.play();
}
}
public class player{
int number;
public int guessnumber(){
number=(int)(Math.random()*10);
return number;
}
}
public class playgame{
public void play(){
while(true){
player p1 = new player(),p2 = new player(),p3 = new player();
int n1,n2,n3;
boolean player1=false,player2=false,player3=false;
int targetnumber;
targetnumber=(int)(Math.random() *10);
System.out.println("target number is :" + targetnumber);
n1=p1.guessnumber();
System.out.println("player 1 is guessing " + n1);
n2=p2.guessnumber();
System.out.println("player 2 is guessing " + n2);
n3=p3.guessnumber();
System.out.println("player 3 is guessing " + n3);
if(targetnumber== n1){
player1=true;
}
if(targetnumber== n2){
player2=true;
}
if(targetnumber== n3){
player3=true;
}
if(player1 || player2 || player3){
System.out.println("we have winner");
if(player1){
System.out.println("winner is player 1" );
}
if(player2){
System.out.println("winner is player2" );
}
if(player3){
System.out.println("winner is player 3 ");
}
break;
}
}
}
}
程序名称与 class 的名称相同,我在 classes 播放器中删除 public 后也找到了解决方案玩游戏,程序没有错误,但我仍然无法理解错误的含义。请帮助我 !!
Public 类 必须有自己的同名文件。但是,如果不是 public,可以将它放在一个不同名称的文件中,
我是 java 中的编程新手,不知道这些错误的含义:
Gamelauncher.java:11: error: class player is public, should be declared in a file named player.java
public class player{
^
Gamelauncher.java:30: error: class playgame is public, should be declared in a file named playgame.java
public class playgame{
^
2 errors
源代码:
public class Gamelauncher{
public static void main(String[] args){
playgame game = new playgame();
game.play();
}
}
public class player{
int number;
public int guessnumber(){
number=(int)(Math.random()*10);
return number;
}
}
public class playgame{
public void play(){
while(true){
player p1 = new player(),p2 = new player(),p3 = new player();
int n1,n2,n3;
boolean player1=false,player2=false,player3=false;
int targetnumber;
targetnumber=(int)(Math.random() *10);
System.out.println("target number is :" + targetnumber);
n1=p1.guessnumber();
System.out.println("player 1 is guessing " + n1);
n2=p2.guessnumber();
System.out.println("player 2 is guessing " + n2);
n3=p3.guessnumber();
System.out.println("player 3 is guessing " + n3);
if(targetnumber== n1){
player1=true;
}
if(targetnumber== n2){
player2=true;
}
if(targetnumber== n3){
player3=true;
}
if(player1 || player2 || player3){
System.out.println("we have winner");
if(player1){
System.out.println("winner is player 1" );
}
if(player2){
System.out.println("winner is player2" );
}
if(player3){
System.out.println("winner is player 3 ");
}
break;
}
}
}
}
程序名称与 class 的名称相同,我在 classes 播放器中删除 public 后也找到了解决方案玩游戏,程序没有错误,但我仍然无法理解错误的含义。请帮助我 !!
Public 类 必须有自己的同名文件。但是,如果不是 public,可以将它放在一个不同名称的文件中,