Show how to solve
package com.codegym.task.task15.task1519;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
/*
Different methods for different types
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try {
while (true)
{
String data = reader.readLine();
if (!(data.equals("exit")))
{
if (data.contains(".") && isDouble(data))
{
Double d = Double.parseDouble(data);
print(d);
}
else if (isInteger(data) && Integer.parseInt(data) > 0 && Integer.parseInt(data) < 128)
{
short s = Short.parseShort(data);
print(s);
}
else if (isInteger(data) && Integer.parseInt(data) <= 0 || Integer.parseInt(data) >= 128)
{
Integer i = Integer.parseInt(data);
print(i);
}
else
{
print(data);
}
}
else
{
break;
}
}
}
catch (Exception e)
{
System.out.println(e);
}
}
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);
}
public static boolean isDouble(String s)
{
Double d = Double.parseDouble(s);
return true;
}
public static boolean isInteger(String s)
{
Integer i = Integer.parseInt(s);
return true;
}
}