Skip to content

Commit

Permalink
Create Dice.java
Browse files Browse the repository at this point in the history
solves dubesar#608 

This is an example of using Math.random for a random integer
  • Loading branch information
mete23 authored Oct 12, 2022
1 parent 893534d commit c7676e1
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Examples/Dice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import java.util.Scanner;

public class Dice {

public static void main(String[] args) {

boolean b = true;
Scanner scanner = new Scanner(System.in);

do {
System.out.println("Give input to roll the dice or write X to exit!");
String a = scanner.next();
if (a.toLowerCase().equals("x")) {
b = false;
} else {
System.out.println((int)(Math.random() * 6 + 1));
}
} while(b);
scanner.close();

}

}

0 comments on commit c7676e1

Please sign in to comment.