Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You may have a combination lock on your locker at school where you have to spin the dial to 3 separate numbers from 0 up

You may have a combination lock on your locker at school where you have to spin the dial to 3 separate numbers from 0 up to 40. What if you forgot your combination? Would you be able to guess it?
Write code that will generate 3 random integers from 0 up to 40(but not including 40) using Math.random() in the Active Code window below. Run it a couple times to see it generate different numbers.
How many times would you need to run it to guess your combination correctly? Let's have the code compute the number of permutations possible in your combination lock using Math.pow(number,exponent). For example, if you had 2 dials on your combination lock where each dial can be set to a digit from 0-9(10 digits), there are 102 possible permutations. In Java, this would be written as Math.pow(10,2) which means 10 to the power of 2. If you start listing all the permutations possible, you can tell that there are 102 or 100 possible permutations for a 2 dial lock from 0-9.
00,01,02,03,04,05,06,07,08,09
10,11,12,13,14,15,16,17,18,19
dots
90,91,92,93,94,95,96,97,98,99
Now what about the combination lock for this challenge? It has 3 dials with 0-40(not including 40) numbers possible on each dial. In general, the formula to use is NumbersPerDialnumberOfDials. Write this using the Math.pow() method in your code and save it into a variable and print out.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions

Question

3. Speak respectfully. Use the students name.

Answered: 1 week ago