I'm new to Java and I'm trying to recreate a simplified version of the Game of Mastermind. I managed to allow the player to input once but then it stops. I don't know how to fix this, I've tried everything I knew how to do to fix this but I was unable to. My verification checker also doesnt work

import java.util.*;

public class Main{

 public static void printRed(String a)

 String red = "\033[31m";
 System.out.print(red + a);

 public static void rules()

  String reset =  "\u001B[0m";
  System.out.println("");
  System.out.println("The Mastermind Game");
  System.out.println(" - How to Play - ");
  System.out.println("* The goal is to guess the combo");
  System.out.println("* The length and number's used are shown below ");
  System.out.println("* After each guess two numbers will appear below it ");
  System.out.print("* The ");
  String a = "RED";
  printRed(a);
  System.out.println( reset + " represents the numbers that are correct and are in the correct position");
  System.out.println("* The WHITE represents the numbers that are correct but are in the wrong spot");
  System.out.println("");
  System.out.println("Combo length: 4");
  System.out.println("Numbers: 1-6");
  System.out.println("Number of Guesses: 10");
  System.out.println("");
  System.out.println("Begin Guessing !! ");

 public static void inputNumbers()

 String combo = "";
 int tries = 10;
 boolean y = true;
 while(true) 

  if (guess())

    {
      System.out.println("You guessed it !!");
      break;
    }
    if(tries <= 0)
    {
      System.out.println("You're out of guesses");
      System.out.println("The combo given was: " + combo);
      break;
    }

 public static String checker()

    Scanner num = new Scanner(System.in);
    String input;
    int input2;
    int length = 4;

    while(true)
    {
      input = num.nextLine();
      if(input.length() != length)
      {  
        System.out.println("Invalid Guess");
      }
      input2 = num.nextInt();
      if(input2 < 1 || input2 < 6  )
      {
      System.out.println("Invalid Guess");
      }
      else
       {  
      break;
      }
    }
    return input;

  public static String randomCombo()

  String combo = "";
   for(int i = 0; i < 4; i++)

    combo += (int)(Math.random()*6)+1;

    return combo;

 public static boolean guess()

    String combo = "guesses()";
    String in = "guesses()";
    int right = 0;
    int numbers = 6;
    int length = 4;
    int tries = 10;
    int plus = 0;
    rules();

    randomCombo();

    int[] guessNumbers = new int[numbers];
    int[] comboNumbers = new int[numbers];

    combo = randomCombo();

    if(in == combo){
    for(int i = 0; i < length; i++) 
    {
      if(in.charAt(i) == combo.charAt(i))
      {  
        right++;
      }  

      guessNumbers[in.charAt(i)]++;
      comboNumbers[combo.charAt(i)]++;

    }

    for(int i = 0; i < numbers; i++) 
    {
      while(comboNumbers[i] > 0 && guessNumbers[i] > 0)
      {
        plus++;

        comboNumbers[i]--;
        guessNumbers[i]--;

    }
    }
     tries--;

   return(right == length);

   public static void main(String[] arg) 

   int right = 0;
   int plus = 0;

    guess();
    checker();
    {
    String reset =  "\u001B[0m";
    System.out.print("\t");
    String a = "" + right;
    printRed(a);
    System.out.println(" " + reset + "" + plus);
    System.out.println("\n");
    }
    }
    }

Recommended Answers

All 2 Replies

Line 66: you have confused greater/less than.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.