Проверил руками, должно работать, что мог упустить?
package com.javarush.task.task15.task1519;
//import com.sun.source.tree.WhileLoopTree;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
/*
Разные методы для разных типов
*/
public class Solution {
public static void main(String[] args) throws IOException {
Scanner input = new Scanner(System.in);
String string = "";
while (true) {
string = input.nextLine();
if (string.equals("exit")) {
break;
}
if (string.matches("(\\d+)\\.(\\d*)")) {
print(Double.parseDouble(string));
} else if (string.matches("(\\-\\d+)||(\\d+)")) {
Integer a = Integer.parseInt(string);
if (a > 0 && a < 128) {
print(a.shortValue());
} else {
print(a.intValue());
}
} else {
print(string);
}
}
}
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);
}
}