Skip to content

This is a tutorial project. JavaBasics_Task_166_V0.1 Demonstrating the NumberFormatException when parsing invalid strings into integers. 220226_1653

License

Notifications You must be signed in to change notification settings

YuriiJavaDev/JavaBasics_Task_166_V0.1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Registration Input Validator (JavaBasics_Task_166_V0.1)

📖 Description

This project simulates a common data-entry error where a user provides non-numeric text in a field expected to contain an integer (e.g., age). It focuses on Java's response to invalid format conversion through the Integer.parseInt() method.

📋 Requirements Compliance

  • Task: Attempt to parse a non-numeric string into an integer.
  • Input: String playerAgeInput = "abc".
  • Method: Integer.parseInt(String).
  • Goal: Observe the NumberFormatException.

🚀 Architectural Stack

  • Java 8+

🏗️ Implementation Details

The Integer.parseInt() method is designed to scan a string for numeric digits. If it encounters characters that cannot be interpreted as part of a number (like "abc"), it throws a NumberFormatException. In a production environment, this is typically handled within a try-catch block to prevent the application from crashing.

📋 Expected result

Exception in thread "main" java.lang.NumberFormatException: For input string: "abc"
	at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
	at java.base/java.lang.Integer.parseInt(Integer.java:588)
	at java.base/java.lang.Integer.parseInt(Integer.java:685)
	at com.yurii.pavlenko.Solution.main(Solution.java:13)

💻 Code Example

Project Structure:

src/com/yurii/pavlenko/
                └── Solution.java

Code

package com.yurii.pavlenko;

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

        String playerAgeInput = "abc";

        int parsedAge = Integer.parseInt(playerAgeInput);

        // This line will never be reached due to the exception
        System.out.println("Parsed Player Age: " + parsedAge);
    }
}

⚖️ License

This project is licensed under the MIT License.

Copyright (c) 2026 Yurii Pavlenko

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files...

License: MIT

About

This is a tutorial project. JavaBasics_Task_166_V0.1 Demonstrating the NumberFormatException when parsing invalid strings into integers. 220226_1653

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages