Question
import java.util.Scanner; public class Die { public static void main(String[] args) { int die1 = (int)(6*Math.random()+1); int die2 = (int)(6*Math.random()+1); int die3 = (int)(6*Math.random()+1); int
import java.util.Scanner;
public class Die
{
public static void main(String[] args)
{
int die1 = (int)(6*Math.random()+1);
int die2 = (int)(6*Math.random()+1);
int die3 = (int)(6*Math.random()+1);
int die4 = (int)(6*Math.random()+1);
int sumOfDice = die1+die2+die3+die4;
Scanner n = new Scanner(System.in);
String name;
boolean r = false;
System.out.println("Hello, What is your name?");
name = n.nextLine();
System.out.println( "Welcome " + name + "! ");
System.out.println( "My name is Danielle Brandt "); System.out.println( "This is a dice game that you will roll 4 dice.");
System.out.println("If you roll a 9, 11, 18, or 24, you will win." + " If you roll a 6, 12, 13, 17, 19, or 23 then you will lose." + " Roll any other number and that number becomes the goal points and you continue to roll." + "If you roll a 13 you lose and if you roll the goal number, you win. " + "LETS PLAY THE GAME! "); System.out.println("You rolled: "+sumOfDice);
if(sumOfDice == 9 || sumOfDice == 11 || sumOfDice == 18 || sumOfDice == 24) {
System.out.println("You Win at Starting Roll!");
}
else if(sumOfDice = 6 || sumOfDice == 13 || sumOfDice == 12 || sumOfDice == 17 || sumOfDice == 19 || sumOfDice == 23) {
System.out.println("You Lose at Starting Roll!");
}
}
}
\\ I cannot figure out what is wrong with this code. When compiling, and error says that the int cannot be converted to a boolean and that the || in the if statement isnt used correctly.
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