Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class assignment3 {
- public static void main(String[] args) {
- int target = 0;
- int random = 0;
- int random2 = 0;
- int count = 0;
- int matches = 0;
- int sum = (random + random2);
- Scanner keyboard = new Scanner(System.in);
- System.out.println("Enter a target (2-12)");
- target = keyboard.nextInt();
- System.out.println("\n Enter number of required matches");
- matches = keyboard.nextInt();
- if (target >= 2 && target <= 12) {
- System.out.println("Your number: " + target);
- }
- else {
- System.out.println("\nInvalid target");
- }
- while (target != sum) {
- random = (int) (1 + 6 * Math.random());
- random2 = (int) (1 + 6 * Math.random());
- sum = (random + random2);
- count++;
- System.out.println("Rolled: (" + random + "," + random2 + ") sum = " + (random + random2));
- if (sum == target)
- while () {
- random = (int) (1 + 6 * Math.random());
- random2 = (int) (1 + 6 * Math.random());
- sum = (random + random2);
- }
- System.out.println("\nGot " + matches + " matches of the target outcome" + target + " in " + count + " rolls");
- else
- continue;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement