I don't know, what I'm doing wrong. Anyone have an idea?
package com.codegym.task.task15.task1519;
import java.io.IOException;
import java.util.Scanner;
/*
Different methods for different types
*/
public class Solution {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
while (true) {
String data = sc.nextLine();
if (data.equals("exit")) {
break;
}
if (data.contains(".")) {
Double d = Double.parseDouble(data);
print((Double) d);
} else if (tryParse(data)) {
int i = Integer.parseInt(data);
if (i > 0 && i < 128) {
print((short) i);
}
if (i <= 0 || i >= 128) {
print(i);
}
} else print(data);
}
sc.close();
}
private static boolean tryParse(String data) {
try {
Integer.parseInt(data);
return true;
} catch (Exception e) {
return false;
}
}
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);
}
}