I made a code to produce a random 3 digit number. I then set up a scanner consol
ID: 3643905 • Letter: I
Question
I made a code to produce a random 3 digit number. I then set up a scanner console for the user to input a number. How would I code this?The program will print the following words in the given circumstance...
"bagels" -- no digits match between the guess and the answer
"fermi"-- printed for each corret digit in a correct position
"pica" for each correct digit in the WRONG position.
Example Run
--------------------------------------
Your guess? 123
pica pica
Your guess? 456
pica
Your guess? 125
pica
Your guess? 236
fermi pica pica
Your guess? 263
pica pica pica
Your guess? 632
You got it right in 6 guesses.
---------------------------------
Here's what I have so far
**target = a method for the random generated answer
** guess = a method for the user input number
public static void fermi (int[] target, int[] guess, boolean [] ???){
for(int i = 0; i < target ; i++);
Explanation / Answer
public static void main(String[] args) { // create random 3 digit number int random = (int)(Math.random()*(999-100))+100; // get user guess Scanner kb = new Scanner(System.in); int numGuesses = 0; System.out.println(random); while(true) { System.out.print("Your guess? "); int input = kb.nextInt(); numGuesses++; // compare digits String temp = ""; int correct = 0; String randomStr = ""+random; String inputStr = ""+input; int i = 0; // look for in place matches while(iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.