Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am trying to create this java program -------My code---- import java.util.Scanner; import java. util.Random; public class Main { public static void main(String[] args) {
I am trying to create this java program
-------My code----
import java.util.Scanner; import java. util.Random; public class Main { public static void main(String[] args) { // Generate a alphabet as a two-digit string Random r = new Random(); String alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; int length = 5; // Prompt the user to enter a guess Scanner input = new Scanner(System.in); System.out.print("Enter your guess pick (two characters): "); String guess = input.nextLine(); // Get letters from alphabet char alphabetDigit1 = alphabet.charAt(0); char alphabetDigit2 = alphabet.charAt(1); char alphabetDigit3 = alphabet.charAt(2); char alphabetDigit4 = alphabet.charAt(3); char alphabetDigit5 = alphabet.charAt(4); // Get letters from guess char guessWord = guess.charAt(0); char guessWord2 = guess.charAt(1); for (int i = 1; iwhen it compares the characters that the user has inputted it keeps saying both are wrong.
Is there anyway to fix this?
Take two alphabet characters from a user and compare them with your first and last characters out of five random characters. Enter your guess pick (two characters): jif Mine is aBoth are wrong Mine is EBoth are wrong Mine is DBoth are wrong Mine is kBoth are wrong Mine is MBoth are wrong
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started