-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHasard.java
More file actions
85 lines (80 loc) · 2.06 KB
/
Hasard.java
File metadata and controls
85 lines (80 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//Lancé de dés JAVA
//Xavier Brosseau
//2015-01-30
public class Hasard
{
public static void main( String args[] )
{
int NbLancer = 0;
try
{
if(args.length <= 0)
{
System.out.println("Aucun parametre:");
System.out.println("Veuillez entrer un nombre de lancer valide");
return;
}
else if (Integer.parseInt(args[0])>=0 && Integer.parseInt(args[0])<=1000000)
{
NbLancer = Integer.parseInt(args[0]);
}
else
{
System.out.println("Parametre hors intervale\n0 - 1,000,000");
return;
}
}
catch( NumberFormatException e )
{
System.out.println("Parametre invalide\n");
return;
}
int tab[] = new int [11];
System.out.println( "Valeur | Nombre d'occurence" );
System.out.println( "-------|-------------------" );
for (int i = 0; i<NbLancer;i++)
{
// génération d'un entier >= 1 et <= 6
int d1 = 1 + ( int )( Math.random() * 6 );
int d2 = 1 + ( int )( Math.random() * 6 );
int somme = d1 + d2;
tab [somme -2]++;
}
Imprimer(tab);
}
static void PrintHashTag(int tab[], int i, int MaxOcurr)
{
int percent = 0;
int caractereMax = 60;
percent = (tab[i-2] * caractereMax / MaxOcurr);
for (int z =0;z<percent;++z)
{
System.out.print( "#" );
}
System.out.println(" "+tab [i-2]);
}
static void Imprimer(int tab[])
{
int MaxOcurr = 1;
for (int i=2; i<=12;++i)
{
if (tab [i-2]>MaxOcurr)
{
MaxOcurr = tab [i-2];
}
}
for (int i=2; i<=12;++i)
{
if (i < 10)
{
System.out.print( " " + i + " | " );
PrintHashTag(tab,i,MaxOcurr);
}
else
{
System.out.print( " " + i + " | " );
PrintHashTag(tab,i,MaxOcurr);
}
}
}
}