712535. Data Type

Basic

Here is the detailed Markdown blog post for the GeeksforGeeks problem:

Data Type

Summary

The problem involves determining the data type of a given value. This requires identifying the type of data (integer, floating-point number, string, etc.) and handling any edge cases that may arise.

Detailed Explanation

To solve this problem, we can use a simple if-else statement to check the type of the given value. Here's a step-by-step breakdown:

  1. Check if the value is an integer by trying to convert it to an integer using a try-catch block. If the conversion fails (i.e., the value is not an integer), then it must be another data type.
  2. If the value is not an integer, check if it's a floating-point number by trying to convert it to a double. Again, if the conversion fails, then it must be a string or some other data type.
  3. If the value is neither an integer nor a floating-point number, then it must be a string.

Here's some sample code in Python:

View on GeeksforGeeks
public String determineDataType(String value) {
    try {
        int intValue = Integer.parseInt(value);
        return "integer";
    } catch (NumberFormatException e) {
        try {
            double floatValue = Double.parseDouble(value);
            return "floating-point number";
        } catch (NumberFormatException e2) {
            return "string";
        }
    }
}

DevExCode

Master coding interviews with Leetcode, system design, TechBit, QuickLearn, DevTips, Tech Battles, and career services.

© 2026 DevExCode. All rights reserved.