Question
Hi, my question is about how to compile a java file on your PC, and be able to run programs. Please a detailed description and
Hi, my question is about how to compile a java file on your PC, and be able to run programs. Please a detailed description and steps to follow would be greatly appreciated thank you so much in advance.
A code I want to test is below:
import java.util.Random;
public class Dice
{
public static void main(String[] args) {
Random r=new Random();
int score1=0;//score of player 1
int score2=0;//score of player 2
boolean turn = true;
while(score1<75 && score2<75){
int roll1=r.nextInt(6)+1;
int roll2=r.nextInt(6)+1;
if(turn){
System.out.println("Player 1 rolls a "+roll1+" and a "+roll2);
score1+=roll1+roll2;
if(roll1!=roll2)
turn=false;
else{
while(roll1==roll2 && score1<75)
{
roll1=r.nextInt(6)+1;
roll2=r.nextInt(6)+1;//integer between 1 and 6
System.out.println("Player 1 has "+score1+" Player 1 gets to roll again Player 1 rolls a "+roll1+" and a "+roll2);
score1+=roll1+roll2;
}
turn=false;
}
System.out.println("Player 1 now has "+score1);
}
else{
System.out.println("Player 2 rolls a "+roll1+" and a "+roll2);
score2+=roll1+roll2;
if(roll1!=roll2)
turn=true;
else{
while(roll1==roll2 && score2<75)
{
roll1=r.nextInt(6)+1;
roll2=r.nextInt(6)+1;//integer between 1 and 6
System.out.println("Player 2 has "+score2+" Player 2 gets to roll again Player 2 rolls a "+roll1+" and a "+roll2);
score2+=roll1+roll2;
}
turn=true;
}
System.out.println("Player 2 now has "+score2);
}
}
if(score1>=score2){
System.out.println("Player 1 wins with a total of "+score1);
}
else{
System.out.println("Player 2 wins with a total of "+score2);
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started