概述
packagethirtynine;publicclassGuessGame{Playerp1;Playerp2;Playerp3;publicvoidstart(){p1=newPlayer();p2=newPlayer();p3=newPlayer();intguessp1=0;intguessp2=0;intguessp3=0;bo...
package thirtynine;
public class GuessGame {
Player p1;
Player p2;
Player p3;
public void start(){
p1=new Player();
p2=new Player();
p3=new Player();
int guessp1=0;
int guessp2=0;
int guessp3=0;
boolean p1isright=false;
boolean p2isright=false;
boolean p3isright=false;
int targetNumber=(int) (Math.random()*10);
System.out.println("im thinking of a number between 0 and 9...");
while(true){
System.out.println("Number to guess is"+targetNumber);
p1.guess();
p2.guess();
p3.guess();
guessp1=p1.number;
System.out.println("Player one guessed"+guessp1);
guessp2=p2.number;
System.out.println("Player two guessed"+guessp2);
guessp3=p3.number;
System.out.println("Player three guessed"+guessp3);
if(guessp1==targetNumber){
p1isright=true;
}
if(guessp2==targetNumber){
p2isright=true;
}
if(guessp3==targetNumber){
p3isright=true;
}
if(p1isright||p2isright||p3isright){
System.out.println("we hava a winner!");
System.out.println("Player one got it right?"+p1isright);
System.out.println("Player two got it right?"+p2isright);
System.out.println("Player three got it right?"+p1isright);
System.out.println("Game is over");
break;
}
else{
System.out.println("Players will hava try again");
}
}
}
public class Player {
int number=0;
public void guess(){
number=(int)(Math.random()*10);
System.out.println("im guessing"+number);
}
}
public class GameLauncher{
public void main(String[] args){
GuessGame game=new GuessGame();
game.start();
}
}
}
展开
最后
以上就是犹豫路人为你收集整理的java程序无错误没有主方法_为什么java代码里有main函数,运行时却说没有main函数,附上代码,没有提示错误,但不能运行!急求答案!...的全部内容,希望文章能够帮你解决java程序无错误没有主方法_为什么java代码里有main函数,运行时却说没有main函数,附上代码,没有提示错误,但不能运行!急求答案!...所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复