Question: Write a java program that simulates Gambler. The gambler gets in stake and goal. Each time he play he will move forward 1 or backwards
Write a java program that simulates Gambler. The gambler gets in stake and goal. Each time he play he will move forward 1 or backwards 1. Each time new value is created. The program should store that value in array. The problem here is that we don't know how many values there will be created. So we need to create array big enough, lets say it can take 1000000 values. If it takes more then it will crash.
Use the following code as a skeleton for javaprogram!
public static void main(String[] args) { int stake = Integer.parseInt(args[0]); // gambler's stating bankroll int goal = Integer.parseInt(args[1]); // gambler's desired bankroll
int cash = stake; while (cash > 0 && cash < goal) { bets++; if (Math.random() < 0.5) cash++; // win $1 else cash--; // lose $1 }
--------------------------------------------------------------------
Can you guys also please stop posting weird or random answers? If you can't answer the question just let it pass? It has been third time I just get weird with random answers. I really need help with this problem.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
