My code runs without error and works as described in the code requirements but fails to validate. Suggestions are appreciated.
Keith
package com.codegym.task.task15.task1519;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import static java.lang.Boolean.valueOf;
/*
Different methods for different types
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String input = "";
while (true) {
input = reader.readLine();
if (input.equalsIgnoreCase("exit")) {
print(input);
break;
} else {
try {
if (input.contains(".")) {
print(Double.parseDouble(input));
} else if (Integer.parseInt(input) > 0 && Integer.parseInt(input) < 128) {
print(Short.parseShort(input));
} else if (Integer.parseInt(input) <= 0 || Integer.parseInt(input) >= 128) {
print(Integer.parseInt(input));
} else {
print(input);
}
} catch (NumberFormatException e) {
print(input);
}
}
}
}
public static void print(Double value) {
System.out.println("This is a Double. Value: " + value);
}
public static void print(String value) {
System.out.println("This is a String. Value: " + value);
}
public static void print(short value) {
System.out.println("This is a short. Value: " + value);
}
public static void print(Integer value) {
System.out.println("This is an Integer. Value: " + value);
}
}