![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#11 |
|
Newbie
Join Date: Nov 2005
Location: Puerto Rico
Posts: 12
Rep Power: 0
![]() |
Here's the code...
This is in a PairOfDice class
public class PairOfDice{
int first_dice;
int second_dice;
int sides=6;
public PairOfDice(){
first_dice=0;
second_dice=0;
}
public void roll(){
first_dice=(int) (Math.random()*sides) + 1;
second_dice=(int) (Math.random()*sides) + 1;
}
}And this is in a BoxCars class public class BoxCars {
public static void main (String[] args){
int counter=0;
PairOfDice GameDices= new PairOfDice();
for(int i=0;i<1000;i++){
GameDices.roll();
if((GameDices.first_dice==6)&&(GameDices.second_dice==6)){
counter++;
}
}
System.out.println("The result of cars is :"+counter);
}
}Check out is that if what you need. ![]()
__________________
From P.R. to the World!! RoBeRt |
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|