Well as Darryl pointed out you will need a loop here (for or while eitehr will work). Also if the problem is that you don't know how to get the square root take a look at this
Math (Java 2 Platform SE v1.4.2)
Java has excellent documentation and tutorials on that site I would recommend that as your first port of call for problems like this. If it's the logic it can often help to define your problem step by step in English or even take a test case (define a number and work through step by step don't think about loops).