You can ask the user to enter the date in a predefined format. Then you can palce it into a String and pass it to your GregorianCalendar calls as you show in your code block.
Here is how you can get a String from the user via console:
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String input = in.readLine();
If your application has a GUI, you can also use following method:
ans = JOptionPane.showInputDialog(null, "Please enter date below:");