---
title: "Discussion on \"Java: String after Integer causing error?\" | Hashnode"
description: "Discussion on \"Java: String after Integer causing error?\". Error while reading a string after an integer"
url: "https://hashnode.com/posts/java-string-after-integer-causing-error/6207cfadd59187113c4c09ba"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Java: String after Integer causing error?](https://sayantanidey.hashnode.dev/java-string-after-integer-causing-error?utm_source=hashnode&utm_medium=feed)

Error while reading a string after an integer

Feb 12, 2022 · 3 min read · sayantanidey.hashnode.dev  
Read the article

-   [#string](https://hashnode.com/tag/string)
-   [#error](https://hashnode.com/tag/error)
-   [#error-handling](https://hashnode.com/tag/error-handling)
-   [#java](https://hashnode.com/tag/java)
-   [#beginners](https://hashnode.com/tag/beginners)

## Written by

[Sayantani Dey](https://hashnode.com/@sayantani-dey)

@sayantani-dey · West Bengal, India

  
[View profile](https://hashnode.com/@sayantani-dey)

It is the errors that lead to insightful study

I am an undergraduate pursuing my bachelors in Computer Science and Engineering. I love to write and enhance web development skills. Web development seems very interesting to me as it is not just coding but also creativity, so I'm gaining knowledge and practising to develop my skills with HTML and CSS.

## Responses 3

Markdown supported · ⌘↵ to post

[Jeevika Sirwani](https://hashnode.com/@JeevikaSirwani)

[Feb 13, 2022](https://hashnode.com/posts/java-string-after-integer-causing-error/6207cfadd59187113c4c09ba/comment/6208a9c585b93114aeba4866)

Crisp and clear.🙌

[Wellington Domiciano](https://hashnode.com/@wldomiciano)

[Feb 12, 2022](https://hashnode.com/posts/java-string-after-integer-causing-error/6207cfadd59187113c4c09ba/comment/62083af0a2be760e35396c3c)

Nice! This is a good way to overcome this situation.

Another approach would be to pass `nextLine()` to `parseInt()`:

```
int year = Integer.parseInt(in.nextLine());
```

I like it better this way because for me it's less confusing than having a `nextLine()` lost between the lines.

[Samadrita Shaw](https://hashnode.com/@shawsamadrita)

[Feb 12, 2022](https://hashnode.com/posts/java-string-after-integer-causing-error/6207cfadd59187113c4c09ba/comment/6207e0c2a2be760e353963b4)

This is very well explained and will definitely help a lot of people. 👏🏼
