You should use a while loop: The dice are rolled again and again until the player has won or lost (then, break
ends the while loop).
while (true) { int dice1=(int)(Math.random()*6+1); int dice2=(int)(Math.random()*6+1); int sum = dice1 + dice2; System.out.println("Roll: total = " + sum); if (sum==2 || sum==3 || sum==12) { System.out.println("Sorry with a " + sum + " You LOSE :("); break; } else if(sum==7 || sum==11) { System.out.println("Woah!!! With a " + sum + " You WIN!!!!!!!"); break; } // If you wanted, you could wait here for the user to confirm (e.g. with a key press) }
Related Posts:
- How do I “decompile” Java class files? [closed]
- How do I compare strings in Java?
- What is the best way to implement constants in Java?
- What is the reason behind “non-static method cannot be referenced from a static context”?
- What does ” || ” mean in Java? [duplicate]
- “Error occurred during initialization of VM; Could not reserve enough space for object heap” using -Xmx3G
- “int cannot be dereferenced” in Java
- What is a Key-Value Pair?
- Create ArrayList from array
- What is null in Java?
- What is an illegal reflective access?
- Convert Set to List without creating new List
- What is a serialVersionUID and why should I use it?
- SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”
- The difference between += and =+
- exception in initializer error in java when using Netbeans
- MacOS Catalina(v 10.15.3): Error: “chromedriver” cannot be opened because the developer cannot be verified. Unable to launch the chrome browser
- Can I catch multiple Java exceptions in the same catch clause?
- What is the use of printStackTrace() method in Java?
- How do I limit the number of decimals printed for a double?
- Please initialize the log4j system properly warning
- how to iterate in List
- > in java and set their values as we do in a normal int a[i][j] matrix type [duplicate]
- Understanding the difference between null and ‘\u000’ in Java
- what does Dead Code mean under Eclipse IDE Problems Section
- Java compressing Strings
- Can an abstract class have a constructor?
- org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when ‘hibernate.dialect’ not set
- “NoClassDefFoundError: Could not initialize class” error
- Recursive print Factorial
- Recompile with -Xlint:unchecked for detail error in java
- Convert array of strings into a string in Java
- What is Serialization?
- SSL and cert keystore
- Generate a random double in a range
- Eclipse “Error: Could not find or load main class”
- How to get locator of current web element?
- javax.naming.NameNotFoundException
- How to print out all the elements of a List in Java?
- If Java is Strongly typed then why does this code compile?
- Error: cannot find symbol ArrayList
- Choosing the best concurrency list in Java
- Why nextLine() and not nextString() ?
- Very Basic Java
- What is the meaning of “%d:%02d” in `printf`?
- Type List vs type ArrayList in Java
- No Persistence provider for EntityManager named
- What does it mean: JavaFX application class must extend javafx.application.Application?
- Using Math.round to round to one decimal place?
- How to replace a substring of a string
- accessing a variable from another class
- “Javac” doesn’t work correctly on Windows 10
- How to convert a byte array to a hex string in Java?
- How to get the last value of an ArrayList
- ArithmeticException: “Non-terminating decimal expansion; no exact representable decimal result”
- How to check if the value is integer in java?
- Java Error: Invalid top level statement
- How to make an array of arrays in Java
- Instantiating object of type parameter
- MultipartException: Current request is not a multipart request
- How to extract a substring using regex
- How are “mvn clean package” and “mvn clean install” different?
- Why are two empty ArrayLists with different generic types equal?
- java.lang.VerifyError: Inconsistent stackmap frames at branch target 421
- How to convert an Instant to a date format?
- equivalent to push() or pop() for arrays?
- JaxbRepresentation gives error “doesnt contain ObjectFactory.class or jaxb.index”
- How do I fix a NoSuchMethodError?
- What is the Java equivalent for LINQ?
- “Expression expected” and “Cannot find symbol” error
- Android Studio ERROR: Cannot resolve symbol ‘View’
- Static Initialization Blocks
- “Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar” when starting the Scala interpreter
- Sending POST data in Android
- When is “java.io.IOException:Connection reset by peer” thrown?
- Java ArrayList of Doubles
- what is update-alternatives command in linux and what is the use of it?
- java: use StringBuilder to insert at the beginning
- Multiple delimiters in Scanner class of Java
- Eclipse Problems View not showing Errors anymore
- unexpected type error
- What does it mean: The serializable class does not declare a static final serialVersionUID field? [duplicate]
- “Cannot be resolved to a type” when attempting to use Scanner
- Converting a 2-3-4 tree into a red black tree
- Generic stack implementation
- Java generating non-repeating random numbers
- java eclipse red exclamation mark
- Java FileOutputStream Create File if not exists
- Configure active profile in SpringBoot via Maven
- Is there any way to program Java on Visual Studio 2015
- android.content.res.Resources$NotFoundException: String resource ID #0x0
- what does x– or x++ do here?
- How to specify filepath in java?
- Issue installing Netbeans in Windows 10: Java SE Development Kit (JDK) was not found on this computer
- dequeue and enqueue methods in queue implementation
- How to specify the default error page in web.xml?
- Exception is never thrown in body of corresponding try statement
- Could not transfer artifact org.apache.maven.plugins:maven-surefire-plugin:pom:2.7.1 from/to central (http://repo1.maven.org/maven2)
- Using while loop as input validation [duplicate]
- java -version and javac -version showing different versions
- when spring boot startup,throw out the “method names must be tokens” exception