import java.io.*;
public class Magic{
static final int maxsize = 50;
public static void main (String [] args) throws IOException{
int i, j, k, l, n, key;
Wrap the try/catch statement with a while loop.
while(not true) {
do foo()
}
Put your code that computes your magic square in a separate method, and have your input reading code in a while loop, that calls that method until the user presses N, for example.
Check out the Scanner class.
String tryAgain = "y";
do
{
// you code
System.out.println("Try again? enter \"y/n\".");
tryAgain = System.in.readLine();
}
while(!tryAgain.equals("n"));