Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class assignment3 {
  4. public static void main(String[] args) {
  5.  
  6. int target = 0;
  7. int random = 0;
  8. int random2 = 0;
  9. int count = 0;
  10. int matches = 0;
  11. int sum = (random + random2);
  12. Scanner keyboard = new Scanner(System.in);
  13.  
  14. System.out.println("Enter a target (2-12)");
  15. target = keyboard.nextInt();
  16.  
  17. System.out.println("\n Enter number of required matches");
  18. matches = keyboard.nextInt();
  19.  
  20. if (target >= 2 && target <= 12) {
  21. System.out.println("Your number: " + target);
  22. }
  23. else {
  24. System.out.println("\nInvalid target");
  25. }
  26.  
  27. while (target != sum) {
  28. random = (int) (1 + 6 * Math.random());
  29. random2 = (int) (1 + 6 * Math.random());
  30. sum = (random + random2);
  31.  
  32. count++;
  33.  
  34. System.out.println("Rolled: (" + random + "," + random2 + ") sum = " + (random + random2));
  35.  
  36. if (sum == target)
  37.  
  38. while () {
  39. random = (int) (1 + 6 * Math.random());
  40. random2 = (int) (1 + 6 * Math.random());
  41. sum = (random + random2);
  42. }
  43. System.out.println("\nGot " + matches + " matches of the target outcome" + target + " in " + count + " rolls");
  44. else
  45. continue;
  46. }
  47.  
  48. }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement