Если содержит точку, всё равно вылетает на стринг
package com.javarush.task.task15.task1519;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Разные методы для разных типов
*/
public class Solution {
public static void main(String[] args) throws IOException {
boolean isFinish = false;
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
while (!isFinish) {
String input = reader.readLine();
if (input.equals("exit")) {
isFinish = true;
}
try {
int checkInt = Integer.parseInt(input);
if (input.contains(".")){
Double doubleOut = Double.parseDouble(input);
print(doubleOut);
} else if (checkInt > 0 && checkInt < 128) {
Short shortOut = Short.parseShort(input);
print(shortOut);
} else if (checkInt <= 0 || checkInt >= 128)
print(checkInt);
} catch (NumberFormatException ex) {
print(input);
}
}
reader.close();
}
public static void print(Double value) {
System.out.println("Это тип Double, значение " + value);
}
public static void print(String value) {
System.out.println("Это тип String, значение " + value);
}
public static void print(short value) {
System.out.println("Это тип short, значение " + value);
}
public static void print(Integer value) {
System.out.println("Это тип Integer, значение " + value);
}
}