---
title: "Take out year from input"  
description: "Take out year from input"  
author: "Anonymous User"  
published: 2015-12-20  
updated: 2015-12-20  
canonical: https://www.mindstick.com/forum/33757/take-out-year-from-input  
category: "java"  
tags: ["java", "string"]  
reading_time: 1 minute  

---

# Take out year from input

My [implementation](https://www.mindstick.com/forum/33764/how-to-implementation-of-class-in-c-sharp) :

```
public class NewClass {    public static void main(String[] args) {        Scanner in = new Scanner(System.in);        System.out.println("Input your place and date birth : ");        String birth = in.nextLine();    }}
```

And I will [input](https://www.mindstick.com/forum/159209/how-can-i-read-convert-an-input-stream-into-a-string-in-java) [MindStick](https://yourviews.mindstick.com/view/84668/how-mindstick-is-used-for-marketing-purposes), 25 Dec 2015. The [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) how to change my input from [string to int](https://www.mindstick.com/forum/12941/how-to-convert-hashmap-keys-from-string-to-int-in-java), and how to take only the year. So I can use for

```
if (2015 - year < 20 ) {    System.out.println ("You are teen");}
```

## Replies

### Reply by David Miller

Hi Mayank ,\
It would be better if you'll split the "input" into two. and then tell the user to enter his/her birthday in this format (Month Day, Year). The comma is important because after the comma the year follows.\

```
int year = 0;String place = "";Scanner place_in = new Scanner(System.in);System.out.print("Enter place of Birth : ");place = place_in.nextLine();String bday = "";Scanner bday_in = new Scanner(System.in);System.out.print("Enter Birthday (Month Day,Year): ");bday = bday_in.nextLine();for(int i=0;i<bday.length();i++) {    if(bday.charAt(i)==','){      year = Integer.parseInt(Character.toString(bday.charAt(i+2))+Character.toString(bday.charAt(i+3))+Character.toString(bday.charAt(i+4))+Character.toString(bday.charAt(i+5)));    }}
```


---

Original Source: https://www.mindstick.com/forum/33757/take-out-year-from-input

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
