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)); System.out.println("Enter values to print: "); String value; /*while(!typein.equals("exit")) { System.out.println("to exit type exit"); int value = Integer.parseInt(typein); if(value > 0 && value < 128) { JavaApplication213.print(value); //public static print } else if(value <= 0 || value <= 128){ JavaApplication213.print(value); }*/ do { value = reader.readLine(); if(value.contentEquals(value)) { String s = value; print(s); } else if(value.contains(".")) { Double d = Double.parseDouble(value); print(d); } else if(Short.parseShort(value) > 0 && Short.parseShort(value) < 128) { short s = Short.parseShort(value); print(s); } else if(Integer.parseInt(value) <= 0 || Integer.parseInt(value)>= 128 ) { Integer i = Integer.parseInt(value); print(i); } //(short)value = value; //value = Integer.parseInt(value); /* public static boolean isNumeric(String value) { if (value == null) { return false; } try { double d = Short.parseShort(value); } catch (NumberFormatException nfe) { return false; } return true; } */ } while(!value.equals("exit")); } //JavaApplication213 javaApplication213 = new JavaApplication213(); 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); } }