-5

Possible Duplicate:
How to convert string to int in Java?

I am trying to figure out how to convert a string that has integers in it to an integer variable.

Code:

import java.util.Scanner;

public class main {
    public static void main(String args[]) {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter date of birth (MM/DD/YYYY):");
        String DOB = input.next();
        String month = DOB.substring(0, 1);
        String day = DOB.substring(3, 4);
        String year = DOB.substring(6, 9);
        int month1 = month;
        int age = 0;
        //age = 2013 - DOB - 1;
        int age2 = 0;
        age2  = age + 1;
        System.out.println("You are " + age + " or " + age2 + " years old");
    }
}

I want to turn String month, String day, and Sting year into integers.

Community
  • 1
  • 1
captainGeech
  • 302
  • 1
  • 5
  • 17
  • 1
    http://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#valueOf%28java.lang.String%29 – Brian Roach Feb 02 '13 at 01:26
  • 6
    Not much of a techgod now are we? Someone already gave you the answer in your [previous question](http://stackoverflow.com/a/14617257/164966), please try to understand answers to your questions before asking more questions. – Roman Feb 02 '13 at 01:28

1 Answers1

15

use int month = Integer.parseInt(stringMonth);

Neil Locketz
  • 4,228
  • 1
  • 23
  • 34