Simple bulls and cows java game : <p>I try to create a verry simple Bulls and Cows game (<a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" rel="nofollow">https://en.wikipedia.org/wiki/Bulls_and_Cows</a>). The game is for my school project. My knowledge is limited, so I need to make the game using only loops, IF-else constructions and other simple functions.</p>

<p>The written code works somewhat - generate code and understands that number is hited, but did not indicate how many cows and bulls have in the wrong assumptions.</p>

<p>I would be glad if someone point me in the right direction :) Thanks in advance</p>

<pre><code>import java.util.Random;
import java.util.Scanner;

public class BCgame{

    public static void main(String[] args){
        Random r= new Random();
        int number= 0;
        int trynum = 0;
        while(uniq(number= (r.nextInt(9000) + 1000)));
        String targetStr = number +"";
        boolean game = true;
        Scanner input = new Scanner(System.in);
        do{
            System.out.println(number);
            int bulls = 0;
            int cows = 0;
            System.out.print("Guess a number: ");
            int guess;
            guess = input.nextInt();
            if (uniq(guess)  || guess &lt; 1000) continue;
            trynum++;
            String guessStr = guess + "";
            for(int i= 0;i &lt; 4;i++){
                if(guessStr.charAt(i) == targetStr.charAt(i)){
                    bulls++;
                }else if(targetStr.contains(guessStr.charAt(i)+"")){
                    cows++;
                }
            }
            if(bulls == 4){
                game = false;
            }else{
                System.out.println(cows+" Cows and "+bulls+" Bulls.");
            }
        }while(game);
        System.out.println("You won after "+trynum+" guesses!");
    }

    public static boolean uniq(int num){
        String checknum = num+"";
        if(checknum.charAt(0) == checknum.charAt(1)) return false;
            else if(checknum.charAt(1) == checknum.charAt(2)) return false;
                else if(checknum.charAt(2) == checknum.charAt(3)) return false;
    return true;
    };
}
</code></pre>
