-3

Well as the title says.. I have a feeling I did something wrong in my code.

import java.util.Scanner;
import java.util.Calendar;

public class AgePrompt
{
    public static void main(String[] args){


        Scanner userInput = new Scanner(System.in);

        String age;
        System.out.print("Enter your date of birth here: ");
        age = userInput.next();

        String myDate = 
        java.text.DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime());


        System.out.println("Your age is: "+myDate);

    }
}

So where did I go wrong?

  • 2
    You do not do any calculations, but just get the current time and print it out. – qqilihq Feb 15 '14 at 14:42
  • 1
    ^ah okay.. makes sense.. my bad, so whats the correct code? – user3312466 Feb 15 '14 at 14:44
  • 2
    Read the javadoc of GregorianCalendar (and its superclass Calendar), and try to find out by yourself. Also, don't name "age" a variable storing a date of birth. Name it "dateOfBirth". – JB Nizet Feb 15 '14 at 14:46
  • I guess, that's your task :) For a quick and dirty solution you might use the milliseconds to determine the age, if you want to do it right, I suggest having a look at the calendar classes. – qqilihq Feb 15 '14 at 14:46
  • ^Thanks for you help guys, I appreciate it. – user3312466 Feb 15 '14 at 14:47
  • I recommend that you use Joda. Here is an example of how to use it: http://stackoverflow.com/questions/1116123/how-do-i-calculate-someones-age-in-java – Rhys Feb 15 '14 at 15:03
  • You went wrong in two places: (a) Not reading the documentation, and (b) not searching Stackoverflow.com before posting. Your question has been asked and answered many times. – Basil Bourque Jun 29 '14 at 20:08

1 Answers1

0

You do not use age in further calculations and print out the result of the current date.

Smutje
  • 16,300
  • 3
  • 20
  • 36