Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I made a code to produce a random 3 digit number. I then set up a scanner consol

ID: 3643918 • 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?

Use arrays.
NO double while loops.
NO break statements.
Methods should be less than 25 lines.



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? 1234
bagels
Your guess? 5678
fermi fermi pica
Your guess? 5566
fermi
Your guess? 5587
fermi pica pica
Your guess? 7578
You got it right in 5 guesses.

Do you want to play again? y
Your guess? 1234
fermi pica
Your guess? 5678
pica
Your guess? 2936
You got it right in 3 guesses.

Do you want to play again? NOPE

Explanation / Answer

import java.util.Random; import java.util.Scanner; public class Guess { public static void main(String args[]) { Scanner sc=new Scanner(System.in); Random randomGenerator = new Random(); int n1,n2,x=1; String s1,s2; char ch='y'; int a[]=new int[4]; StringBuffer dis=new StringBuffer(); n1=randomGenerator.nextInt(9999); int i; do { System.out.printf("Your guess?"); n2=sc.nextInt(); s1=Integer.toString(n1); s2=Integer.toString(n2); i=0; while(i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote