|
|
Line 1: |
Line 1: |
| {{1010PrAD | | {{1010PrAD |
| | | |
− | |ProblemName=Roulett | + | |ProblemName=Hello World |
| | | |
| |Problem=The problem | | |Problem=The problem |
Revision as of 14:28, 5 April 2010
Back to the Program-A-Day homepage
Problem
The problem
|
|
...by students
Taken from http://www.flickr.com/photos/daniello/565304023/
An image or By Students section
|
Solution
The solution...
|
Code
Solution Code
import java.lang.Math.*;
import javax.swing.*;
public class Roulett
{
public static void main(String[] args)
{
boolean win = false;
int money = 100;
for(int i = 0; i < 20; i++)
{
double probability = 0.2;
for(int j = 0; j < 6; j++)
{
double chance = Math.random();
if(probability > chance)
{
if(j % 2 == 0)
{
money -= 50;
win = false;
}
else
{
money += 50;
win = true;
}
}
if(j < 4)
{
probability += 0.1;
}
else
{
probability += 0.25;
}
}
}
JOptionPane.showMessageDialog(null, "Player's money left: " + money);
}
}
|
Back to the Program-A-Day homepage