The obvious problem with the while loop above (besides it not being written properly, it is merely a demonstration) is that the variable will change only in class1 or maybe create an error when trying to create a new instance of a class with the same name.

My question is:

How can I write the while loop in such a way that the class name will change (for example from class1 to class2) automatically when the user enters another integer?

--------------------------------------------

What I have tried (but probably not done correctly) is to create a variable className and then have the while loop look like this:

Class class+className = new class ();
className = className +1;

This didn't work and I'm guessing its for obvious reasons though I don't see them (too much of a newbie) :(

First of all, you really can't do what you're trying to do, but more importantly, you don't want to. The variable name is not as important as you think it is and for all intents and purposes doesn't really exist when the program is running. What is more important is having references to objects, not having names for object variables. So if you want to create a bunch of MyClass objects, each with a different int property, I recommend creating an ArrayList of MyClass, and then filling it with MyClass objects as you create them, something like: