Hi,
first I thought that the problem was in not doing the try/catch on converting, but the validator will not accept even the double (I know that some try/catch blocks are missing) and it will not accept "exit". I know that I have some stupid mistake there regarding the understanding of the assignment, I just don't know where.
Thanks for pointers!
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 {
//write your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
while (true){
String readIn = reader.readLine();
if (readIn.equals("exit")){break;}
else if (readIn.contains("."))
{
try{
double d = Double.parseDouble(readIn);
print(d);}
catch(Exception e){}
}
else if (Integer.parseInt(readIn) > 0 && Integer.parseInt(readIn) < 128){
short d = (short) (Integer.parseInt(readIn));
print(d);
}
else if (Integer.parseInt(readIn) <= 0 || Integer.parseInt(readIn) >= 128){
Integer d = Integer.parseInt(readIn);
print(d);
}
else{
print(readIn);
}
}
}
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);
}
}