What is wrong here? I tried to do this task without instanceof and it didn't work at all, but now it always calls print with String
package pl.codegym.task.task15.task1519;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
/*
Różne metody dla różnych typów
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
while (true) {
Object input = reader.readLine();
String help = (String) input;
if (help.equals("exit"))
break;
if (input instanceof Double) {
char[] c = help.toCharArray();
for (int i = 0; i < c.length; i++) {
if (c[i] == '.') {
double d = Double.parseDouble(help);
print(d);
}
}
}
if (input instanceof Short) {
Short s = Short.parseShort(help);
if ((s > 0) && (s < 128))
print(s);
}
else if (input instanceof Integer) {
Integer in = Integer.parseInt(help);
if (in >= 128)
print(in);
}
else
print(help);
}
}
public static void print(Double value) {
System.out.println("To jest Double. Value: " + value);
}
public static void print(String value) {
System.out.println("To jest String. Value: " + value);
}
public static void print(short value) {
System.out.println("To jest liczba całkowita typu short. Value: " + value);
}
public static void print(Integer value) {
System.out.println("To jest liczba całkowita typu Integer. Value: " + value);
}
}