The Math.random() Questions (4 days)
Write a method that will print out 10 random numbers between 1 and 100.
public void printTen()
Write a method that will receive two numbers and will then return out a random number between the two (inclusively)
public int getNumber(int lo, int hi)
Write a method that will generate 50 random numbers between 1 and 100 and will then print out the sum and the average .
public void printStats()
Write a program that will pick a number between 1 and 100 and then let you guess the number. It will tell you that you got it (and end program) or tell you your guess was too high or too low and let you continue guessing.
Simulate the rolling of a pair of dice 100 times. How many times did you roll 7?
public int numberOfSevens()
Simulate the flipping of a coin 1000 times. How many times was it heads.
public int numberOfHeads()
Simulate a fortune teller. You push a key and 1 of 5 fortunes comes out.
public void printFortunes()
Monte Carlo Approximation - If I start with 48 dice and roll them and remove all 2's, how many rolls will it take until all the dice are removed. Run simulation (with a loop) 1 million times and find the average of how many rolls it would take on average.
public double getRolls()
Print out 1 of 6 names at random.
public void printName()
Print out a number at random between 1 and 37
public void printNumber1()
Between -100 and 100
public void printNumber2()
Between -15 and 25
public void printNumber3()
Between -30 and -20
public void printNumber4()
Between -1 and 1
public void printNumber5()
Either -1 or 1
public void printNumber6()
3, 5 or 7
public void printNumber7()
- Write a method that will generate 50 random numbers between 1 and 100 and print out the average, the smallest number and the biggest number.
public void printStuff()
- Write a method that will print out a random addition problem (numbers between 1 and 37) and will let you type in an answer and will then tell you if you are right or wrong.
public void mathProblem()
12 + 4 =
- Write a method that will print out 5 even numbers at random between 1 and 100.
public void print5Even()
Write a method that will do the same as number 18 except that it will ask you 10 random math questions and then give you a score at the end (use a loop)
- Rolling Two in a Row: Write a program that rolls a die 1000 times and counts the number of times the same result occurs twice in a row. In your counting, you should consider a sequence 3 3 3 as containing two sets of identical rolls -- the middle 3 matches the first, and the third 3 matches the second. Thus, the following sequence of rolls would be counted as having the same result occur twice in a row for 4 times.
1 5 3 2 4 4 6 5 5 5 3 6 2 1 1 2
public int twiceinarow()
- Write a program that will generate 2 random integers between 1 and 100 that when multiplied togeteher equals 4221. Print the answer and return how many tries it took the computer to get the result?
public int getCount()
- Three coins are tossed 100,000 times. What is the probability that the first head is flipped on the third toss. (what % of the time will this occur)
public int getPercent()
- Same as above except, what is the probability that no heads are tossed.
public int getPercent2()
- As a code to get into her bank account SAM JONES used 3 random letters from his name (Ex. NES, ASA). Write a method that will keep generating 3 letter strings from his name until it matches the target password. Return how many attempts it took to find the key and print out what the key was.
private String key = "MAJ";
public int printKey()
Simulate the rolling of 4 dice. What percentage of the time will you get at least 1 match?