Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 KB | None | 0 0
  1. package TP;
  2.  
  3. import java.util.Random;
  4.  
  5. public class tp2 {
  6.    
  7.     public static int d1;
  8.     public static int d2;
  9.     public static int d3;
  10.     public static int qvu[] = {4, 2, 1};
  11.  
  12.     public static void main(String[] args) {
  13.        
  14.         rdmD();
  15.         check();
  16.        
  17.         //System.out.println("Dé 1 : " + d1 + " Dé 2 : " + d2 + " Dé 3 : " + d3);
  18.         System.out.println("  ");
  19.        
  20.     }
  21.    
  22.     public static void rdmD() {
  23.        
  24.         Random rand = new Random();
  25.         d1 = rand.nextInt(6) + 1;
  26.         d2 = rand.nextInt(6) + 1;
  27.         d3 = rand.nextInt(6) + 1;
  28.     }
  29.    
  30.     public static void check() {
  31.         int i = 0;
  32.         int j = 0;
  33.         int k = 0;
  34.        
  35.         int winD1 = 0;
  36.         int winD2 = 0;
  37.         int winD3 = 0;
  38.         while (i < qvu.length && d1 != qvu[i]) {
  39.             i++;
  40.         }
  41.        
  42.         if(i < qvu.length) {
  43.             System.out.println("Le D1 est tombé sur " + d1);
  44.             winD1 = 1;
  45.            
  46.         } else {
  47.             System.out.println("Le D1 est tombé sur " + d1);
  48.         }
  49.        
  50.         while (j < qvu.length && d2 != qvu[j]) {
  51.             j++;
  52.         }
  53.        
  54.         if(j < qvu.length) {
  55.             System.out.println("Le D2 est tombé sur " + d2);
  56.             winD2 = 1;
  57.         } else {
  58.             System.out.println("Le D2 est tombé sur " + d2);
  59.         }
  60.        
  61.         while (k < qvu.length && d3 != qvu[k]) {
  62.             k++;
  63.         }
  64.        
  65.         if(k < qvu.length) {
  66.             System.out.println("Le D3 est tombé sur " + d3);
  67.             winD3 = 1;
  68.         } else {
  69.             System.out.println("Le D3 est tombé sur " + d3);
  70.         }
  71.        
  72.         if (d1 == d2 || d2 == d3 || d3 == d1) {
  73.             System.out.println("Deux dés ont la même valeur, c'est perdu");
  74.         } else if (winD1 == 1 && winD2 == 1 && winD3 == 1) {
  75.             System.out.println("Vous avez gagné");
  76.         } else {
  77.             System.out.println("C'est perdu");
  78.         }
  79.        
  80.     }
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement