"Guess my Number" in Java I have just started learning Java, and don't want to start any bad habits, so please review my latest game code:

import java.util.Random;
import java.util.Scanner;
class GuessMyNumber {
    public static void main(String args[]) {
        Random random = new Random();
        Scanner input = new Scanner(System.in);
        int MIN = 1;
        int MAX = 100;
        int comp = random.nextInt(MAX - MIN + 1) + MIN;
        int user;
        int guesses = 0;
        do {
            System.out.print("Guess a number between 1 and 100: ");
            user = input.nextInt();
            guesses++;
            if (user &gt; comp)
                System.out.println("My number is less than " + user + ".");
            else if (user &lt; comp)
                System.out.println("My number is greater than " + user + ".");
            else
                System.out.println("Well done! " + comp + " was my number! You guessed it in " + guesses + " guesses.");
        } while (user != comp);
    }
}
So although this code is a small example it still can benefit from having a few methods sprinkled in to help clear up what you are trying to do. For instance what if you decided that you wanted to change the max and min to be entered in as a parameter to starting the program? You would have to change max and min to be equal to the int value of args[0] and args[1] although for a small example that is not a big deal, but it would be a little more simple to of had a method similar to this.

//gets deafult secret number
private int getSecretNumber(){
    int MIN = 1;
    int MAX = 100;

    return  getSecretNumber(MAX, MIN);
}
//converts a string variable to a int and returns a secret number
private int getSecretNumber(String strMax, String strMin){
    //code to convert string to int
    getSecretNumber(max, min);
}
//generates a secret number between 2 numbers
private int getSecretNumber(int MAX, int MIN){
    return random.nextInt(MAX - MIN + 1) + MIN;
}


Now you will have saved your self some time in the future if/when the design requirements change. if implemented correctly you might not have any code changes.. say something like this.

public static void main(String args[]) {
    int comp = getSecretNumber(); //gets default
    if (args.length == 2)
        comp = getSecretNumber(args[0], args[1]);

    //etc...


It is always a good idea to seperate your business code and your logic code. The business code is the rules for your code. "Do A,B,C give me D, and Save to E" the logic code is the nitty gritty details of how to do A-E. Everyone calls it something different but the concept is always the same. Keep the two as seperate as possible it makes changing your code easier.

Those are my tips. Other than that I don't see any problems with your code other than you don't have a way to escape the loop other than guessing the correct number.